

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>pysimm.system &mdash; pysimm 0.2 documentation</title>
  

  
  

  

  
  
    

  

  
  
    <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  

  

  
    <link rel="top" title="pysimm 0.2 documentation" href="../../index.html"/>
        <link rel="up" title="pysimm" href="../pysimm.html"/> 

  
  <script src="../../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="../../index.html" class="icon icon-home"> pysimm
          

          
          </a>

          
            
            
              <div class="version">
                0.2
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
                <ul>
<li class="toctree-l1"><a class="reference internal" href="../../pysimm.html">pysimm package</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="../../index.html">pysimm</a>
      </nav>


      
      <div class="wy-nav-content">
        <div class="rst-content">
          





<div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="../../index.html">Docs</a> &raquo;</li>
      
          <li><a href="../index.html">Module code</a> &raquo;</li>
      
          <li><a href="../pysimm.html">pysimm</a> &raquo;</li>
      
    <li>pysimm.system</li>
      <li class="wy-breadcrumbs-aside">
        
          
        
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for pysimm.system</h1><div class="highlight"><pre>
<span></span><span class="c1"># ******************************************************************************</span>
<span class="c1"># pysimm.system module</span>
<span class="c1"># ******************************************************************************</span>
<span class="c1">#</span>
<span class="c1"># ******************************************************************************</span>
<span class="c1"># License</span>
<span class="c1"># ******************************************************************************</span>
<span class="c1"># The MIT License (MIT)</span>
<span class="c1">#</span>
<span class="c1"># Copyright (c) 2016 Michael E. Fortunato</span>
<span class="c1">#</span>
<span class="c1"># Permission is hereby granted, free of charge, to any person obtaining a copy</span>
<span class="c1"># of this software and associated documentation files (the &quot;Software&quot;), to deal</span>
<span class="c1"># in the Software without restriction, including without limitation the rights</span>
<span class="c1"># to use, copy, modify, merge, publish, distribute, sublicense, and/or sell</span>
<span class="c1"># copies of the Software, and to permit persons to whom the Software is</span>
<span class="c1"># furnished to do so, subject to the following conditions:</span>
<span class="c1">#</span>
<span class="c1"># The above copyright notice and this permission notice shall be included in</span>
<span class="c1"># all copies or substantial portions of the Software.</span>
<span class="c1">#</span>
<span class="c1"># THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</span>
<span class="c1"># IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
<span class="c1"># FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE</span>
<span class="c1"># AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
<span class="c1"># LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,</span>
<span class="c1"># OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN</span>
<span class="c1"># THE SOFTWARE.</span>

<span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">print_function</span>

<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">json</span>
<span class="kn">from</span> <span class="nn">xml.etree</span> <span class="kn">import</span> <span class="n">ElementTree</span> <span class="k">as</span> <span class="n">Et</span>
<span class="kn">from</span> <span class="nn">random</span> <span class="kn">import</span> <span class="n">random</span>
<span class="kn">from</span> <span class="nn">StringIO</span> <span class="kn">import</span> <span class="n">StringIO</span>
<span class="kn">from</span> <span class="nn">urllib2</span> <span class="kn">import</span> <span class="n">urlopen</span><span class="p">,</span> <span class="n">HTTPError</span><span class="p">,</span> <span class="n">URLError</span>
<span class="kn">from</span> <span class="nn">itertools</span> <span class="kn">import</span> <span class="n">permutations</span>
<span class="kn">from</span> <span class="nn">math</span> <span class="kn">import</span> <span class="n">sin</span><span class="p">,</span> <span class="n">cos</span><span class="p">,</span> <span class="n">sqrt</span><span class="p">,</span> <span class="n">pi</span><span class="p">,</span> <span class="n">acos</span><span class="p">,</span> <span class="n">floor</span><span class="p">,</span> <span class="n">ceil</span>


<span class="k">try</span><span class="p">:</span>
    <span class="kn">from</span> <span class="nn">subprocess</span> <span class="kn">import</span> <span class="n">call</span>
<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
    <span class="n">call</span> <span class="o">=</span> <span class="bp">None</span>
<span class="k">try</span><span class="p">:</span>
    <span class="kn">import</span> <span class="nn">numpy</span> <span class="kn">as</span> <span class="nn">np</span>
<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
    <span class="n">np</span> <span class="o">=</span> <span class="bp">None</span>

<span class="kn">from</span> <span class="nn">pysimm</span> <span class="kn">import</span> <span class="n">calc</span>
<span class="kn">from</span> <span class="nn">pysimm</span> <span class="kn">import</span> <span class="n">error_print</span>
<span class="kn">from</span> <span class="nn">pysimm</span> <span class="kn">import</span> <span class="n">warning_print</span>
<span class="kn">from</span> <span class="nn">pysimm</span> <span class="kn">import</span> <span class="n">verbose_print</span>
<span class="kn">from</span> <span class="nn">pysimm</span> <span class="kn">import</span> <span class="n">debug_print</span>
<span class="kn">from</span> <span class="nn">pysimm</span> <span class="kn">import</span> <span class="n">PysimmError</span>
<span class="kn">from</span> <span class="nn">pysimm.calc</span> <span class="kn">import</span> <span class="n">rotate_vector</span>
<span class="kn">from</span> <span class="nn">pysimm.utils</span> <span class="kn">import</span> <span class="n">PysimmError</span><span class="p">,</span> <span class="n">Item</span><span class="p">,</span> <span class="n">ItemContainer</span>


<div class="viewcode-block" id="Particle"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.Particle">[docs]</a><span class="k">class</span> <span class="nc">Particle</span><span class="p">(</span><span class="n">Item</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.system.Particle</span>

<span class="sd">    Objects inheriting from :class:`~pysimm.utils.Item` can contain arbitrary data.</span>
<span class="sd">    Keyword arguments are assigned as attributes.</span>
<span class="sd">    Attributes usually used are given below.</span>
<span class="sd">    </span>
<span class="sd">    Attributes:</span>
<span class="sd">        x: x coordinate</span>
<span class="sd">        y: y coordinate</span>
<span class="sd">        z: z coordinate</span>
<span class="sd">        charge: partial charge</span>
<span class="sd">        type: :class:`~ParticleType` object reference</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">Item</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        
<div class="viewcode-block" id="Particle.coords"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.Particle.coords">[docs]</a>    <span class="k">def</span> <span class="nf">coords</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">z</span><span class="p">)</span></div>

<div class="viewcode-block" id="Particle.check"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.Particle.check">[docs]</a>    <span class="k">def</span> <span class="nf">check</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">style</span><span class="o">=</span><span class="s1">&#39;full&#39;</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">style</span> <span class="o">==</span> <span class="s1">&#39;full&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">x</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="n">error_print</span><span class="p">(</span><span class="s1">&#39;particle </span><span class="si">%s</span><span class="s1"> has no x coordinate&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">tag</span><span class="p">)</span>
                <span class="k">return</span> <span class="bp">False</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">y</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="k">return</span> <span class="bp">False</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">z</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="k">return</span> <span class="bp">False</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">charge</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="k">return</span> <span class="bp">False</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="ow">is</span> <span class="bp">None</span> <span class="ow">or</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">check</span><span class="p">():</span>
                <span class="k">return</span> <span class="bp">False</span>
            <span class="k">return</span> <span class="bp">True</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">error_print</span><span class="p">(</span><span class="s1">&#39;style </span><span class="si">%s</span><span class="s1"> not supported yet&#39;</span> <span class="o">%</span> <span class="n">style</span><span class="p">)</span>
            <span class="k">return</span> <span class="bp">False</span></div>

<div class="viewcode-block" id="Particle.delete_bonding"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.Particle.delete_bonding">[docs]</a>    <span class="k">def</span> <span class="nf">delete_bonding</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">s</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.Particle.delete_bonding</span>

<span class="sd">        Iterates through s.bonds, s.angles, s.dihedrals, and s.impropers and removes</span>
<span class="sd">        those which contain this :class:`~pysimm.system.Particle`.</span>

<span class="sd">        Args:</span>
<span class="sd">            s: :class:`~pysimm.system.System` object from which bonding objects will be removed</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">b</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">bonds</span><span class="p">:</span>
                    <span class="n">s</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">bonds</span><span class="p">:</span>
                <span class="k">if</span> <span class="bp">self</span> <span class="ow">is</span> <span class="n">b</span><span class="o">.</span><span class="n">a</span> <span class="ow">or</span> <span class="bp">self</span> <span class="ow">is</span> <span class="n">b</span><span class="o">.</span><span class="n">b</span><span class="p">:</span>
                    <span class="n">s</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">angles</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">angles</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">a</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">angles</span><span class="p">:</span>
                    <span class="n">s</span><span class="o">.</span><span class="n">angles</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">angles</span><span class="p">:</span>
                <span class="k">if</span> <span class="bp">self</span> <span class="ow">is</span> <span class="n">a</span><span class="o">.</span><span class="n">a</span> <span class="ow">or</span> <span class="bp">self</span> <span class="ow">is</span> <span class="n">a</span><span class="o">.</span><span class="n">b</span> <span class="ow">or</span> <span class="bp">self</span> <span class="ow">is</span> <span class="n">a</span><span class="o">.</span><span class="n">c</span><span class="p">:</span>
                    <span class="n">s</span><span class="o">.</span><span class="n">angles</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedrals</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedrals</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">dihedrals</span><span class="p">:</span>
                    <span class="n">s</span><span class="o">.</span><span class="n">dihedrals</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">tag</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">dihedrals</span><span class="p">:</span>
                <span class="k">if</span> <span class="bp">self</span> <span class="ow">is</span> <span class="n">d</span><span class="o">.</span><span class="n">a</span> <span class="ow">or</span> <span class="bp">self</span> <span class="ow">is</span> <span class="n">d</span><span class="o">.</span><span class="n">b</span> <span class="ow">or</span> <span class="bp">self</span> <span class="ow">is</span> <span class="n">d</span><span class="o">.</span><span class="n">c</span> <span class="ow">or</span> <span class="bp">self</span> <span class="ow">is</span> <span class="n">d</span><span class="o">.</span><span class="n">d</span><span class="p">:</span>
                    <span class="n">s</span><span class="o">.</span><span class="n">dihedrals</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">tag</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">impropers</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">impropers</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">impropers</span><span class="p">:</span>
                    <span class="n">s</span><span class="o">.</span><span class="n">impropers</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">i</span><span class="o">.</span><span class="n">tag</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">impropers</span><span class="p">:</span>
                <span class="k">if</span> <span class="bp">self</span> <span class="ow">is</span> <span class="n">i</span><span class="o">.</span><span class="n">a</span> <span class="ow">or</span> <span class="bp">self</span> <span class="ow">is</span> <span class="n">i</span><span class="o">.</span><span class="n">b</span> <span class="ow">or</span> <span class="bp">self</span> <span class="ow">is</span> <span class="n">i</span><span class="o">.</span><span class="n">c</span> <span class="ow">or</span> <span class="bp">self</span> <span class="ow">is</span> <span class="n">i</span><span class="o">.</span><span class="n">d</span><span class="p">:</span>
                    <span class="n">s</span><span class="o">.</span><span class="n">impropers</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">i</span><span class="o">.</span><span class="n">tag</span><span class="p">)</span></div>
                    
<div class="viewcode-block" id="Particle.translate"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.Particle.translate">[docs]</a>    <span class="k">def</span> <span class="nf">translate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dx</span><span class="p">,</span> <span class="n">dy</span><span class="p">,</span> <span class="n">dz</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.Particle.translate</span>
<span class="sd">        </span>
<span class="sd">        Shifts Particle position by dx, dy, dz.</span>
<span class="sd">        </span>
<span class="sd">        Args:</span>
<span class="sd">            dx: distance to shift in x direction</span>
<span class="sd">            dy: distance to shift in y direction</span>
<span class="sd">            dz: distance to shift in z direction</span>
<span class="sd">        </span>
<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">x</span> <span class="o">+=</span> <span class="n">dx</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">y</span> <span class="o">+=</span> <span class="n">dy</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">z</span> <span class="o">+=</span> <span class="n">dz</span></div>

    <span class="k">def</span> <span class="fm">__sub__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.Particle.__sub__</span>

<span class="sd">        Implements subtraction between :class:`~pysimm.system.Particle` objects to calculate distance.</span>

<span class="sd">        Args:</span>
<span class="sd">            other: :class:`~pysimm.system.Particle` object</span>

<span class="sd">        Returns:</span>
<span class="sd">            distance calculated by :func:`~pysimm.calc.distance`. This does not consider pbc</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="n">Particle</span><span class="p">):</span>
            <span class="k">return</span> <span class="n">calc</span><span class="o">.</span><span class="n">distance</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">None</span>

    <span class="k">def</span> <span class="fm">__rsub__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="fm">__sub__</span><span class="p">(</span><span class="n">other</span><span class="p">)</span></div>


<div class="viewcode-block" id="ParticleType"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.ParticleType">[docs]</a><span class="k">class</span> <span class="nc">ParticleType</span><span class="p">(</span><span class="n">Item</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.system.ParticleType</span>

<span class="sd">    Objects inheriting from :class:`~pysimm.utils.Item` can contain arbitrary data.</span>
<span class="sd">    Keyword arguments are assigned as attributes.</span>
<span class="sd">    Attributes usually used are given below.</span>

<span class="sd">    Attributes:</span>
<span class="sd">        sigma: LJ sigma value (Angstrom)</span>
<span class="sd">        epsilon: LJ epsilon value (kcal/mol)</span>
<span class="sd">        elem: element abbreviation, i.e. &#39;H&#39; for Hydrogen, &#39;Cl&#39; for Chlorine</span>
<span class="sd">        name: force field particle type name</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">Item</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></div>
        
        
<div class="viewcode-block" id="Bond"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.Bond">[docs]</a><span class="k">class</span> <span class="nc">Bond</span><span class="p">(</span><span class="n">Item</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.system.Bond</span>
<span class="sd">    </span>
<span class="sd">    Bond between particle a and b</span>
<span class="sd">    </span>
<span class="sd">    a--b</span>

<span class="sd">    Objects inheriting from :class:`~pysimm.utils.Item` can contain arbitrary data.</span>
<span class="sd">    Keyword arguments are assigned as attributes.</span>
<span class="sd">    Attributes usually used are given below.</span>

<span class="sd">    Attributes:</span>
<span class="sd">        a: :class:`~pysimm.system.Particle` object involved in bond</span>
<span class="sd">        b: :class:`~pysimm.system.Particle` object involved in bond</span>
<span class="sd">        type: BondType object reference</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">Item</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        
<div class="viewcode-block" id="Bond.get_other_particle"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.Bond.get_other_particle">[docs]</a>    <span class="k">def</span> <span class="nf">get_other_particle</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">p</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">p</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">a</span> <span class="ow">and</span> <span class="n">p</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">b</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">None</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">a</span> <span class="k">if</span> <span class="n">p</span> <span class="ow">is</span> <span class="bp">self</span><span class="o">.</span><span class="n">b</span> <span class="k">else</span> <span class="bp">self</span><span class="o">.</span><span class="n">b</span></div>

<div class="viewcode-block" id="Bond.distance"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.Bond.distance">[docs]</a>    <span class="k">def</span> <span class="nf">distance</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.Bond.distance</span>

<span class="sd">        Calculates distance between :class:`~pysimm.system.Particle` a and :class:`~pysimm.system.Particle` b in this Bond object.</span>
<span class="sd">        Sets distance to dist attribute of self. Does not consider pbc.</span>

<span class="sd">        Args:</span>
<span class="sd">            None</span>

<span class="sd">        Returns:</span>
<span class="sd">            Distance between Particle a and Particle b (not considering pbc)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">a</span><span class="p">,</span> <span class="n">Particle</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">b</span><span class="p">,</span> <span class="n">Particle</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">dist</span> <span class="o">=</span> <span class="n">calc</span><span class="o">.</span><span class="n">distance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">a</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">b</span><span class="p">)</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">dist</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">None</span></div></div>


<div class="viewcode-block" id="BondType"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.BondType">[docs]</a><span class="k">class</span> <span class="nc">BondType</span><span class="p">(</span><span class="n">Item</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.system.BondType</span>

<span class="sd">    Objects inheriting from :class:`~pysimm.utils.Item` can contain arbitrary data.</span>
<span class="sd">    Keyword arguments are assigned as attributes.</span>
<span class="sd">    Attributes usually used are given below.</span>

<span class="sd">    Attributes:</span>
<span class="sd">        k: harmonic bond force constant (kcal/mol/A^2)</span>
<span class="sd">        r0: bond equilibrium distance (Angstrom)</span>
<span class="sd">        name: force field bond type name</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">Item</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">rname</span> <span class="o">=</span> <span class="s1">&#39;,&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">reversed</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;,&#39;</span><span class="p">)))</span></div>


<div class="viewcode-block" id="Angle"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.Angle">[docs]</a><span class="k">class</span> <span class="nc">Angle</span><span class="p">(</span><span class="n">Item</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.system.Angle</span>
<span class="sd">    </span>
<span class="sd">    Angle between particles a, b, and c</span>
<span class="sd">    </span>
<span class="sd">    a--b--c</span>

<span class="sd">    Objects inheriting from :class:`~pysimm.utils.Item` can contain arbitrary data.</span>
<span class="sd">    Keyword arguments are assigned as attributes.</span>
<span class="sd">    Attributes usually used are given below.</span>

<span class="sd">    Attributes:</span>
<span class="sd">        a: :class:`~pysimm.system.Particle` object involved in angle</span>
<span class="sd">        b: :class:`~pysimm.system.Particle` object involved in angle (middle particle)</span>
<span class="sd">        c: :class:`~pysimm.system.Particle` object involved in angle</span>
<span class="sd">        type: AngleType object reference</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">Item</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

<div class="viewcode-block" id="Angle.angle"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.Angle.angle">[docs]</a>    <span class="k">def</span> <span class="nf">angle</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">radians</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.Angle.angle</span>

<span class="sd">        Calculate angle.</span>

<span class="sd">        Args:</span>
<span class="sd">            radians: True to return value in radians (default: False)</span>

<span class="sd">        Returns:</span>
<span class="sd">            Angle between Particle a, b, and c</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">theta</span> <span class="o">=</span> <span class="n">calc</span><span class="o">.</span><span class="n">angle</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">a</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">b</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">c</span><span class="p">,</span> <span class="n">radians</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">theta</span></div></div>


<div class="viewcode-block" id="AngleType"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.AngleType">[docs]</a><span class="k">class</span> <span class="nc">AngleType</span><span class="p">(</span><span class="n">Item</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.system.AngleType</span>

<span class="sd">    Objects inheriting from :class:`~pysimm.utils.Item` can contain arbitrary data.</span>
<span class="sd">    Keyword arguments are assigned as attributes.</span>
<span class="sd">    Attributes usually used are given below.</span>

<span class="sd">    Attributes:</span>
<span class="sd">        k: harmonic angle bend force constant (kcal/mol/radian^2)</span>
<span class="sd">        theta0: angle equilibrium value (degrees)</span>
<span class="sd">        name: force field angle type name</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">Item</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">rname</span> <span class="o">=</span> <span class="s1">&#39;,&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">reversed</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;,&#39;</span><span class="p">)))</span></div>


<div class="viewcode-block" id="Dihedral"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.Dihedral">[docs]</a><span class="k">class</span> <span class="nc">Dihedral</span><span class="p">(</span><span class="n">Item</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.system.Dihedral</span>
<span class="sd">    </span>
<span class="sd">    Dihedral between particles a, b, c, and d</span>
<span class="sd">    </span>
<span class="sd">    a--b--c--d</span>

<span class="sd">    Objects inheriting from :class:`~pysimm.utils.Item` can contain arbitrary data.</span>
<span class="sd">    Keyword arguments are assigned as attributes.</span>
<span class="sd">    Attributes usually used are given below.</span>

<span class="sd">    Attributes:</span>
<span class="sd">        a: :class:`~pysimm.system.Particle` object involved in dihedral</span>
<span class="sd">        b: :class:`~pysimm.system.Particle` object involved in dihedral (middle particle)</span>
<span class="sd">        c: :class:`~pysimm.system.Particle` object involved in dihedral (middle particle)</span>
<span class="sd">        d: :class:`~pysimm.system.Particle` object involved in dihedral</span>
<span class="sd">        type: :class:`~pysimm.system.DihedralType` object reference</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">Item</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></div>


<div class="viewcode-block" id="DihedralType"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.DihedralType">[docs]</a><span class="k">class</span> <span class="nc">DihedralType</span><span class="p">(</span><span class="n">Item</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.system.DihedralType</span>

<span class="sd">    Objects inheriting from :class:`~pysimm.utils.Item` can contain arbitrary data.</span>
<span class="sd">    Keyword arguments are assigned as attributes.</span>
<span class="sd">    Attributes usually used are given below.</span>

<span class="sd">    Attributes:</span>
<span class="sd">        k: dihedral energy barrier (kcal/mol)</span>
<span class="sd">        d: minimum (+1 or -1)</span>
<span class="sd">        n: multiplicity (integer &gt;= 0)</span>
<span class="sd">        name: force field dihedral type name</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">Item</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">rname</span> <span class="o">=</span> <span class="s1">&#39;,&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">reversed</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;,&#39;</span><span class="p">)))</span></div>


<div class="viewcode-block" id="Improper"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.Improper">[docs]</a><span class="k">class</span> <span class="nc">Improper</span><span class="p">(</span><span class="n">Item</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.system.Improper</span>
<span class="sd">    </span>
<span class="sd">    Improper dihedral around particle a, bonded to b, c, and d</span>
<span class="sd">    </span>
<span class="sd">    | b</span>
<span class="sd">    | |</span>
<span class="sd">    | a--d</span>
<span class="sd">    | |</span>
<span class="sd">    | c</span>
<span class="sd">      </span>
<span class="sd">    Objects inheriting from :class:`~pysimm.utils.Item` can contain arbitrary data.</span>
<span class="sd">    Keyword arguments are assigned as attributes.</span>
<span class="sd">    Attributes usually used are given below.</span>

<span class="sd">    Attributes:</span>
<span class="sd">        a: :class:`~pysimm.system.Particle` object involved in improper (middle particle)</span>
<span class="sd">        b: :class:`~pysimm.system.Particle` object involved in improper</span>
<span class="sd">        c: :class:`~pysimm.system.Particle` object involved in improper</span>
<span class="sd">        d: :class:`~pysimm.system.Particle` object involved in improper</span>
<span class="sd">        type: :class:`~pysimm.system.ImproperType` object reference</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">Item</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></div>


<div class="viewcode-block" id="ImproperType"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.ImproperType">[docs]</a><span class="k">class</span> <span class="nc">ImproperType</span><span class="p">(</span><span class="n">Item</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.system.ImproperType</span>

<span class="sd">    Objects inheriting from :class:`~pysimm.utils.Item` can contain arbitrary data.</span>
<span class="sd">    Keyword arguments are assigned as attributes.</span>
<span class="sd">    Attributes usually used are given below.</span>

<span class="sd">    Attributes:</span>
<span class="sd">        k: improper energy barrier (kcal/mol)</span>
<span class="sd">        x0: equilibrium value (degrees)</span>
<span class="sd">        name: force field improper type name</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">Item</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">rname</span> <span class="o">=</span> <span class="s1">&#39;,&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">reversed</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;,&#39;</span><span class="p">)))</span></div>


<div class="viewcode-block" id="Dimension"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.Dimension">[docs]</a><span class="k">class</span> <span class="nc">Dimension</span><span class="p">(</span><span class="n">Item</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.system.Dimension</span>

<span class="sd">    Objects inheriting from :class:`~pysimm.utils.Item` can contain arbitrary data.</span>
<span class="sd">    Keyword arguments are assigned as attributes.</span>
<span class="sd">    Attributes usually used are given below.</span>

<span class="sd">    Attributes:</span>
<span class="sd">        xlo: minimum value in x dimension</span>
<span class="sd">        xhi: maximum value in x dimension</span>
<span class="sd">        ylo: minimum value in y dimension</span>
<span class="sd">        yhi: maximum value in y dimension</span>
<span class="sd">        zlo: minimum value in z dimension</span>
<span class="sd">        zhi: maximum value in z dimension</span>
<span class="sd">        dx: distance in x dimension</span>
<span class="sd">        dy: distance in y dimension</span>
<span class="sd">        dz: distance in z dimension</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">Item</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="k">if</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">center</span> <span class="ow">and</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">dx</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">dy</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">dz</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">):</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">center</span> <span class="ow">is</span> <span class="bp">True</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">center</span> <span class="o">=</span> <span class="p">[</span><span class="mf">0.</span><span class="p">,</span> <span class="mf">0.</span><span class="p">,</span> <span class="mf">0.</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">xlo</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">dx</span><span class="o">/</span><span class="mf">2.</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">center</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">xhi</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dx</span><span class="o">/</span><span class="mf">2.</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">center</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">ylo</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">dy</span><span class="o">/</span><span class="mf">2.</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">center</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">yhi</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dy</span><span class="o">/</span><span class="mf">2.</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">center</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">zlo</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">dz</span><span class="o">/</span><span class="mf">2.</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">center</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">zhi</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dz</span><span class="o">/</span><span class="mf">2.</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">center</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">xhi</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">xlo</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">dx</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">xhi</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">xlo</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">yhi</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">ylo</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">dy</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">yhi</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">ylo</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">zhi</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">zlo</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">dz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">zhi</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">zlo</span>

<div class="viewcode-block" id="Dimension.check"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.Dimension.check">[docs]</a>    <span class="k">def</span> <span class="nf">check</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">xlo</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">xhi</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">ylo</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">yhi</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">zlo</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">zhi</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">)</span> <span class="ow">and</span>
                <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dx</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">dy</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span>
                 <span class="bp">self</span><span class="o">.</span><span class="n">dz</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">)):</span>
            <span class="k">return</span> <span class="bp">True</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">center</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">dx</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">dy</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">dz</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">True</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">False</span></div>
            
<div class="viewcode-block" id="Dimension.size"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.Dimension.size">[docs]</a>    <span class="k">def</span> <span class="nf">size</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dx</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">xhi</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">xlo</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dy</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">yhi</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">ylo</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">zhi</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">zlo</span>
        <span class="k">return</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dx</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dy</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dz</span><span class="p">)</span></div>
        
<div class="viewcode-block" id="Dimension.translate"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.Dimension.translate">[docs]</a>    <span class="k">def</span> <span class="nf">translate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.Dimension.translate</span>
<span class="sd">        </span>
<span class="sd">        Shifts box bounds by x, y, z.</span>
<span class="sd">        </span>
<span class="sd">        Args:</span>
<span class="sd">            x: distance to shift box bounds in x direction</span>
<span class="sd">            y: distance to shift box bounds in y direction</span>
<span class="sd">            z: distance to shift box bounds in z direction</span>
<span class="sd">        </span>
<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">xlo</span> <span class="o">+=</span> <span class="n">x</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">xhi</span> <span class="o">+=</span> <span class="n">x</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ylo</span> <span class="o">+=</span> <span class="n">y</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">yhi</span> <span class="o">+=</span> <span class="n">y</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">zlo</span> <span class="o">+=</span> <span class="n">z</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">zhi</span> <span class="o">+=</span> <span class="n">z</span></div></div>


<div class="viewcode-block" id="System"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System">[docs]</a><span class="k">class</span> <span class="nc">System</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.system.System</span>

<span class="sd">    Object representation of molecular system.</span>
<span class="sd">    Contains information required for molecular simulation.</span>

<span class="sd">    Attributes:</span>
<span class="sd">        dim: Dimension object reference</span>
<span class="sd">        particles: :class:`~pysimm.utils.ItemContainer` for Particle organization</span>
<span class="sd">        particle_types: :class:`~pysimm.utils.ItemContainer` for ParticleType organization</span>
<span class="sd">        bonds: :class:`~pysimm.utils.ItemContainer` for Bond organization</span>
<span class="sd">        bond_types: :class:`~pysimm.utils.ItemContainer` for BondType organization</span>
<span class="sd">        angles: :class:`~pysimm.utils.ItemContainer` for Angle organization</span>
<span class="sd">        angle_types: :class:`~pysimm.utils.ItemContainer` for AngleType organization</span>
<span class="sd">        dihedrals: :class:`~pysimm.utils.ItemContainer` for Dihedral organization</span>
<span class="sd">        dihedral_types: :class:`~pysimm.utils.ItemContainer` for DihedralType organization</span>
<span class="sd">        impropers: :class:`~pysimm.utils.ItemContainer` for Improper organization</span>
<span class="sd">        improper_types: :class:`~pysimm.utils.ItemContainer` for ImproperType organization</span>
<span class="sd">        molecules: :class:`~pysimm.utils.ItemContainer` for Molecule organization</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">objectified</span> <span class="o">=</span> <span class="bp">False</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;name&#39;</span><span class="p">,</span> <span class="s1">&#39;pySIMM System Object&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ff_class</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;ff_class&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">forcefield</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;forcefield&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dim</span> <span class="o">=</span> <span class="n">Dimension</span><span class="p">(</span><span class="n">xlo</span><span class="o">=</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;xlo&#39;</span><span class="p">),</span> <span class="n">xhi</span><span class="o">=</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;xhi&#39;</span><span class="p">),</span>
                             <span class="n">ylo</span><span class="o">=</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;ylo&#39;</span><span class="p">),</span> <span class="n">yhi</span><span class="o">=</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;yhi&#39;</span><span class="p">),</span>
                             <span class="n">zlo</span><span class="o">=</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;zlo&#39;</span><span class="p">),</span> <span class="n">zhi</span><span class="o">=</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;zhi&#39;</span><span class="p">),</span>
                             <span class="n">dx</span><span class="o">=</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;dx&#39;</span><span class="p">),</span> <span class="n">dy</span><span class="o">=</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;dy&#39;</span><span class="p">),</span>
                             <span class="n">dz</span><span class="o">=</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;dz&#39;</span><span class="p">),</span> <span class="n">center</span><span class="o">=</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;center&#39;</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dim_check</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">check</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mass</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;mass&#39;</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;particle_types&#39;</span><span class="p">,</span> <span class="n">ItemContainer</span><span class="p">())</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bond_types</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;bond_types&#39;</span><span class="p">,</span> <span class="n">ItemContainer</span><span class="p">())</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;angle_types&#39;</span><span class="p">,</span> <span class="n">ItemContainer</span><span class="p">())</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;dihedral_types&#39;</span><span class="p">,</span> <span class="n">ItemContainer</span><span class="p">())</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;improper_types&#39;</span><span class="p">,</span> <span class="n">ItemContainer</span><span class="p">())</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">molecule_types</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;molecule_types&#39;</span><span class="p">,</span> <span class="n">ItemContainer</span><span class="p">())</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">particles</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;particles&#39;</span><span class="p">,</span> <span class="n">ItemContainer</span><span class="p">())</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;bonds&#39;</span><span class="p">,</span> <span class="n">ItemContainer</span><span class="p">())</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">angles</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;angles&#39;</span><span class="p">,</span> <span class="n">ItemContainer</span><span class="p">())</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dihedrals</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;dihedrals&#39;</span><span class="p">,</span> <span class="n">ItemContainer</span><span class="p">())</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">impropers</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;impropers&#39;</span><span class="p">,</span> <span class="n">ItemContainer</span><span class="p">())</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">molecules</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;molecules&#39;</span><span class="p">,</span> <span class="n">ItemContainer</span><span class="p">())</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">write_coeffs</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;write_coeffs&#39;</span><span class="p">,</span> <span class="bp">True</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">set_mass</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_volume</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_density</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_cog</span><span class="p">()</span>

    <span class="k">def</span> <span class="fm">__getattr__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">None</span>

<div class="viewcode-block" id="System.copy"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.copy">[docs]</a>    <span class="k">def</span> <span class="nf">copy</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">rotate_x</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">rotate_y</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">rotate_z</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
             <span class="n">dx</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">dy</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">dz</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.copy</span>

<span class="sd">        Create duplicate :class:`~pysimm.system.System` object. Default behavior does not modify particle positions.</span>

<span class="sd">        Args:</span>
<span class="sd">            rotate_x: rotate duplicate system around x axis by this value (radians)</span>
<span class="sd">            rotate_y: rotate duplicate system around y axis by this value (radians)</span>
<span class="sd">            rotate_z: rotate duplicate system around z axis by this value (radians)</span>
<span class="sd">            dx: translate duplicate system in x dimension by this value (Angstrom)</span>
<span class="sd">            dy: translate duplicate system in y dimension by this value (Angstrom)</span>
<span class="sd">            dz: translate duplicate system in z dimension by this value (Angstrom)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">new</span> <span class="o">=</span> <span class="n">System</span><span class="p">()</span>

        <span class="n">new</span><span class="o">.</span><span class="n">ff_class</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ff_class</span>
        <span class="n">new</span><span class="o">.</span><span class="n">forcefield</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forcefield</span>
        <span class="n">new</span><span class="o">.</span><span class="n">pair_style</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">pair_style</span>
        <span class="n">new</span><span class="o">.</span><span class="n">bond_style</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bond_style</span>
        <span class="n">new</span><span class="o">.</span><span class="n">angle_style</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">angle_style</span>
        <span class="n">new</span><span class="o">.</span><span class="n">dihedral_style</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_style</span>
        <span class="n">new</span><span class="o">.</span><span class="n">improper_style</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">improper_style</span>

        <span class="n">new</span><span class="o">.</span><span class="n">dim</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>

        <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">molecules</span><span class="p">:</span>
            <span class="n">new</span><span class="o">.</span><span class="n">molecules</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">Molecule</span><span class="p">())</span>

        <span class="k">for</span> <span class="n">pt</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="p">:</span>
            <span class="n">new</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">pt</span><span class="o">.</span><span class="n">copy</span><span class="p">())</span>

        <span class="k">for</span> <span class="n">bt</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bond_types</span><span class="p">:</span>
            <span class="n">new</span><span class="o">.</span><span class="n">bond_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">bt</span><span class="o">.</span><span class="n">copy</span><span class="p">())</span>

        <span class="k">for</span> <span class="n">at</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="p">:</span>
            <span class="n">new</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">at</span><span class="o">.</span><span class="n">copy</span><span class="p">())</span>

        <span class="k">for</span> <span class="n">dt</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">:</span>
            <span class="n">new</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">dt</span><span class="o">.</span><span class="n">copy</span><span class="p">())</span>

        <span class="k">for</span> <span class="n">it</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="p">:</span>
            <span class="n">new</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">it</span><span class="o">.</span><span class="n">copy</span><span class="p">())</span>

        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="n">new_p</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
            <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="p">:</span>
                <span class="n">new_p</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">new</span><span class="o">.</span><span class="n">particle_types</span><span class="p">[</span><span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">tag</span><span class="p">]</span>
            <span class="n">new_p</span><span class="o">.</span><span class="n">molecule</span> <span class="o">=</span> <span class="n">new</span><span class="o">.</span><span class="n">molecules</span><span class="p">[</span><span class="n">p</span><span class="o">.</span><span class="n">molecule</span><span class="o">.</span><span class="n">tag</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">rotate_x</span> <span class="ow">or</span> <span class="n">rotate_y</span> <span class="ow">or</span> <span class="n">rotate_z</span><span class="p">:</span>
                <span class="n">new_p</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">new_p</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">new_p</span><span class="o">.</span><span class="n">z</span> <span class="o">=</span> <span class="n">rotate_vector</span><span class="p">(</span><span class="n">new_p</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">new_p</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">new_p</span><span class="o">.</span><span class="n">z</span><span class="p">,</span>
                                                   <span class="n">rotate_x</span><span class="p">,</span> <span class="n">rotate_y</span><span class="p">,</span> <span class="n">rotate_z</span><span class="p">)</span>
            <span class="n">new_p</span><span class="o">.</span><span class="n">x</span> <span class="o">+=</span> <span class="n">dx</span>
            <span class="n">new_p</span><span class="o">.</span><span class="n">y</span> <span class="o">+=</span> <span class="n">dy</span>
            <span class="n">new_p</span><span class="o">.</span><span class="n">z</span> <span class="o">+=</span> <span class="n">dz</span>

            <span class="n">new</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">new_p</span><span class="p">)</span>
            <span class="n">new_p</span><span class="o">.</span><span class="n">molecule</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">new_p</span><span class="p">)</span>
            <span class="n">new_p</span><span class="o">.</span><span class="n">bonds</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>
            <span class="n">new_p</span><span class="o">.</span><span class="n">angles</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>
            <span class="n">new_p</span><span class="o">.</span><span class="n">dihedrals</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>
            <span class="n">new_p</span><span class="o">.</span><span class="n">impropers</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>

        <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="p">:</span>
            <span class="n">new_b</span> <span class="o">=</span> <span class="n">b</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
            <span class="n">new_b</span><span class="o">.</span><span class="n">a</span> <span class="o">=</span> <span class="n">new</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">b</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">]</span>
            <span class="n">new_b</span><span class="o">.</span><span class="n">b</span> <span class="o">=</span> <span class="n">new</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">b</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">b</span><span class="o">.</span><span class="n">type</span><span class="p">:</span>
                <span class="n">new_b</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">new</span><span class="o">.</span><span class="n">bond_types</span><span class="p">[</span><span class="n">b</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">tag</span><span class="p">]</span>
            <span class="n">new</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">new_b</span><span class="p">)</span>
            <span class="n">new_b</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">molecule</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">new_b</span><span class="p">)</span>
            <span class="n">new_b</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">new_b</span><span class="p">)</span>
            <span class="n">new_b</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">new_b</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">angles</span><span class="p">:</span>
            <span class="n">new_a</span> <span class="o">=</span> <span class="n">Angle</span><span class="p">(</span><span class="n">a</span><span class="o">=</span><span class="n">new</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">a</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">],</span>
                          <span class="n">b</span><span class="o">=</span><span class="n">new</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">a</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">],</span>
                          <span class="n">c</span><span class="o">=</span><span class="n">new</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">a</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">tag</span><span class="p">])</span>
            <span class="k">if</span> <span class="n">a</span><span class="o">.</span><span class="n">type</span><span class="p">:</span>
                <span class="n">new_a</span><span class="o">.</span><span class="n">type</span><span class="o">=</span><span class="n">new</span><span class="o">.</span><span class="n">angle_types</span><span class="p">[</span><span class="n">a</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">tag</span><span class="p">]</span>
            <span class="n">new</span><span class="o">.</span><span class="n">angles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">new_a</span><span class="p">)</span>
            <span class="n">new_a</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">molecule</span><span class="o">.</span><span class="n">angles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">new_a</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedrals</span><span class="p">:</span>
            <span class="n">new_d</span> <span class="o">=</span> <span class="n">Dihedral</span><span class="p">(</span><span class="n">a</span><span class="o">=</span><span class="n">new</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">d</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">],</span>
                             <span class="n">b</span><span class="o">=</span><span class="n">new</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">d</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">],</span>
                             <span class="n">c</span><span class="o">=</span><span class="n">new</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">d</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">tag</span><span class="p">],</span>
                             <span class="n">d</span><span class="o">=</span><span class="n">new</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">d</span><span class="o">.</span><span class="n">d</span><span class="o">.</span><span class="n">tag</span><span class="p">])</span>
            <span class="k">if</span> <span class="n">d</span><span class="o">.</span><span class="n">type</span><span class="p">:</span>
                <span class="n">new_d</span><span class="o">.</span><span class="n">type</span><span class="o">=</span><span class="n">new</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">[</span><span class="n">d</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">tag</span><span class="p">]</span>
            <span class="n">new</span><span class="o">.</span><span class="n">dihedrals</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">new_d</span><span class="p">)</span>
            <span class="n">new_d</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">molecule</span><span class="o">.</span><span class="n">dihedrals</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">new_d</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">impropers</span><span class="p">:</span>
            <span class="n">new_i</span> <span class="o">=</span> <span class="n">Improper</span><span class="p">(</span><span class="n">a</span><span class="o">=</span><span class="n">new</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">],</span>
                             <span class="n">b</span><span class="o">=</span><span class="n">new</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">],</span>
                             <span class="n">c</span><span class="o">=</span><span class="n">new</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">tag</span><span class="p">],</span>
                             <span class="n">d</span><span class="o">=</span><span class="n">new</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="o">.</span><span class="n">d</span><span class="o">.</span><span class="n">tag</span><span class="p">])</span>
            <span class="k">if</span> <span class="n">i</span><span class="o">.</span><span class="n">type</span><span class="p">:</span>
                <span class="n">new_i</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">new</span><span class="o">.</span><span class="n">improper_types</span><span class="p">[</span><span class="n">i</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">tag</span><span class="p">]</span>
            <span class="n">new</span><span class="o">.</span><span class="n">impropers</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">new_i</span><span class="p">)</span>
            <span class="n">new_i</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">molecule</span><span class="o">.</span><span class="n">impropers</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">new_i</span><span class="p">)</span>
            
        <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="nb">vars</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">ItemContainer</span><span class="p">)</span> <span class="ow">and</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">Item</span><span class="p">):</span>
                <span class="nb">setattr</span><span class="p">(</span><span class="n">new</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">new</span></div>

<div class="viewcode-block" id="System.add"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.add">[docs]</a>    <span class="k">def</span> <span class="nf">add</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.add</span>

<span class="sd">        Add other :class:`~pysimm.system.System` to this. Optionally remove duplicate types (default behavior).</span>

<span class="sd">        Args:</span>
<span class="sd">            other: :class:`~pysimm.system.System` object to add</span>
<span class="sd">            unique_types (optional): Remove duplicate types and reassign references to existing types (True)</span>
<span class="sd">            change_dim (optional): Update :class:`~pysimm.system.Dimension` object so that :class:`~pysimm.system.Particle` objects do not exist</span>
<span class="sd">                                   outside of :class:`~pysimm.system.Dimension` extremes (True)</span>
<span class="sd">            update_properties (optional): Update system-wide mass, volume, density, center of gravity, and velocity</span>
<span class="sd">                                          properties (True)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">unique_types</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;unique_types&#39;</span><span class="p">,</span> <span class="bp">True</span><span class="p">)</span>
        <span class="n">change_dim</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;change_dim&#39;</span><span class="p">,</span> <span class="bp">True</span><span class="p">)</span>
        <span class="n">update_properties</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;update_properties&#39;</span><span class="p">,</span> <span class="bp">True</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">pt</span> <span class="ow">in</span> <span class="n">other</span><span class="o">.</span><span class="n">particle_types</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">unique_types</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">pt</span><span class="o">.</span><span class="n">name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="n">x</span><span class="o">.</span><span class="n">name</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="p">]:</span>
                    <span class="k">del</span> <span class="n">pt</span><span class="o">.</span><span class="n">tag</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">pt</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">del</span> <span class="n">pt</span><span class="o">.</span><span class="n">tag</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">pt</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">bt</span> <span class="ow">in</span> <span class="n">other</span><span class="o">.</span><span class="n">bond_types</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">unique_types</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">bt</span><span class="o">.</span><span class="n">name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="n">x</span><span class="o">.</span><span class="n">name</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bond_types</span><span class="p">]:</span>
                    <span class="k">del</span> <span class="n">bt</span><span class="o">.</span><span class="n">tag</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">bond_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">bt</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">del</span> <span class="n">bt</span><span class="o">.</span><span class="n">tag</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">bond_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">bt</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">at</span> <span class="ow">in</span> <span class="n">other</span><span class="o">.</span><span class="n">angle_types</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">unique_types</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">at</span><span class="o">.</span><span class="n">name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="n">x</span><span class="o">.</span><span class="n">name</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="p">]:</span>
                    <span class="k">del</span> <span class="n">at</span><span class="o">.</span><span class="n">tag</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">at</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">del</span> <span class="n">at</span><span class="o">.</span><span class="n">tag</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">at</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">dt</span> <span class="ow">in</span> <span class="n">other</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">unique_types</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">dt</span><span class="o">.</span><span class="n">name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="n">x</span><span class="o">.</span><span class="n">name</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">]:</span>
                    <span class="k">del</span> <span class="n">dt</span><span class="o">.</span><span class="n">tag</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">dt</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">del</span> <span class="n">dt</span><span class="o">.</span><span class="n">tag</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">dt</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">it</span> <span class="ow">in</span> <span class="n">other</span><span class="o">.</span><span class="n">improper_types</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">unique_types</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">it</span><span class="o">.</span><span class="n">name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="n">x</span><span class="o">.</span><span class="n">name</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="p">]:</span>
                    <span class="k">del</span> <span class="n">it</span><span class="o">.</span><span class="n">tag</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">it</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">del</span> <span class="n">it</span><span class="o">.</span><span class="n">tag</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">it</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">other</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="k">del</span> <span class="n">p</span><span class="o">.</span><span class="n">tag</span>
            <span class="k">if</span> <span class="n">change_dim</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xhi</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xhi</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xlo</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xlo</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">yhi</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">yhi</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">ylo</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">ylo</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zhi</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">z</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zhi</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zlo</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">z</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zlo</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">unique_types</span> <span class="ow">and</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="p">:</span>
                <span class="n">pt</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">pt</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">pt</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
                    <span class="n">error_print</span><span class="p">(</span><span class="s1">&#39;ParticleType error&#39;</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">pt</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="n">other</span><span class="o">.</span><span class="n">bonds</span><span class="p">:</span>
            <span class="k">del</span> <span class="n">b</span><span class="o">.</span><span class="n">tag</span>
            <span class="k">if</span> <span class="n">unique_types</span> <span class="ow">and</span> <span class="n">b</span><span class="o">.</span><span class="n">type</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bond_types</span><span class="p">:</span>
                <span class="n">bt</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bond_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">bt</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">bt</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
                    <span class="n">error_print</span><span class="p">(</span><span class="s1">&#39;BondType error&#39;</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">b</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">bt</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">b</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="n">other</span><span class="o">.</span><span class="n">angles</span><span class="p">:</span>
            <span class="k">del</span> <span class="n">a</span><span class="o">.</span><span class="n">tag</span>
            <span class="k">if</span> <span class="n">unique_types</span> <span class="ow">and</span> <span class="n">a</span><span class="o">.</span><span class="n">type</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="p">:</span>
                <span class="n">at</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">at</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">at</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
                    <span class="n">error_print</span><span class="p">(</span><span class="s1">&#39;AngleType error&#39;</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">a</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">at</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">angles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">other</span><span class="o">.</span><span class="n">dihedrals</span><span class="p">:</span>
            <span class="k">del</span> <span class="n">d</span><span class="o">.</span><span class="n">tag</span>
            <span class="k">if</span> <span class="n">unique_types</span> <span class="ow">and</span> <span class="n">d</span><span class="o">.</span><span class="n">type</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">:</span>
                <span class="n">dt</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">dt</span><span class="p">:</span>
                    <span class="n">error_print</span><span class="p">(</span><span class="s1">&#39;DihedralType error&#39;</span><span class="p">)</span>
                <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">dt</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
                    <span class="n">index</span> <span class="o">=</span> <span class="mi">0</span>
                    <span class="n">x</span> <span class="o">=</span> <span class="mi">5</span>
                    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">dt</span><span class="p">)):</span>
                        <span class="k">if</span> <span class="n">dt</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">count</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">x</span><span class="p">:</span>
                            <span class="n">index</span> <span class="o">=</span> <span class="n">i</span>
                            <span class="n">x</span> <span class="o">=</span> <span class="n">dt</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">count</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">)</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">dt</span><span class="p">[</span><span class="n">index</span><span class="p">]</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">dt</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">dihedrals</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">other</span><span class="o">.</span><span class="n">impropers</span><span class="p">:</span>
            <span class="k">del</span> <span class="n">i</span><span class="o">.</span><span class="n">tag</span>
            <span class="k">if</span> <span class="n">unique_types</span> <span class="ow">and</span> <span class="n">i</span><span class="o">.</span><span class="n">type</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="p">:</span>
                <span class="n">it</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">i</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">it</span><span class="p">:</span>
                    <span class="n">error_print</span><span class="p">(</span><span class="s1">&#39;ImproperType error&#39;</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">i</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">it</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">impropers</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">m</span> <span class="ow">in</span> <span class="n">other</span><span class="o">.</span><span class="n">molecules</span><span class="p">:</span>
            <span class="k">del</span> <span class="n">m</span><span class="o">.</span><span class="n">tag</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">molecules</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
            <span class="n">p_list</span> <span class="o">=</span> <span class="n">m</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;all&#39;</span><span class="p">)</span>
            <span class="n">m</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s1">&#39;all&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">p_list</span><span class="p">:</span>
                <span class="n">m</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">update_properties</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">set_mass</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">set_volume</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">set_density</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">set_cog</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">set_velocity</span><span class="p">()</span></div>

<div class="viewcode-block" id="System.distance"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.distance">[docs]</a>    <span class="k">def</span> <span class="nf">distance</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">p1</span><span class="p">,</span> <span class="n">p2</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.distance</span>

<span class="sd">        Calculate distance between two particles considering pbc.</span>

<span class="sd">        Args:</span>
<span class="sd">            p1: :class:`~pysimm.system.Particle` object</span>
<span class="sd">            p2: :class:`~pysimm.system.Particle` object</span>

<span class="sd">        Returns:</span>
<span class="sd">            distance between particles considering pbc</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">calc</span><span class="o">.</span><span class="n">pbc_distance</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">p1</span><span class="p">,</span> <span class="n">p2</span><span class="p">)</span></div>

<div class="viewcode-block" id="System.wrap"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.wrap">[docs]</a>    <span class="k">def</span> <span class="nf">wrap</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.wrap</span>

<span class="sd">        Wrap :class:`~pysimm.system.Particle` images into box defined by :class:`~pysimm.system.Dimension` object.</span>
<span class="sd">        Ensure particles are contained within simulation box.</span>

<span class="sd">        Args:</span>
<span class="sd">            None</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">check</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="k">while</span> <span class="n">p</span><span class="o">.</span><span class="n">x</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xhi</span><span class="p">:</span>
                <span class="n">p</span><span class="o">.</span><span class="n">x</span> <span class="o">-=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dx</span>
            <span class="k">while</span> <span class="n">p</span><span class="o">.</span><span class="n">x</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xlo</span><span class="p">:</span>
                <span class="n">p</span><span class="o">.</span><span class="n">x</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dx</span>
            <span class="k">while</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">yhi</span><span class="p">:</span>
                <span class="n">p</span><span class="o">.</span><span class="n">y</span> <span class="o">-=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dy</span>
            <span class="k">while</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">ylo</span><span class="p">:</span>
                <span class="n">p</span><span class="o">.</span><span class="n">y</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dy</span>
            <span class="k">while</span> <span class="n">p</span><span class="o">.</span><span class="n">z</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zhi</span><span class="p">:</span>
                <span class="n">p</span><span class="o">.</span><span class="n">z</span> <span class="o">-=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dz</span>
            <span class="k">while</span> <span class="n">p</span><span class="o">.</span><span class="n">z</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zlo</span><span class="p">:</span>
                <span class="n">p</span><span class="o">.</span><span class="n">z</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dz</span></div>

<div class="viewcode-block" id="System.unwrap"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.unwrap">[docs]</a>    <span class="k">def</span> <span class="nf">unwrap</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.unwrap()</span>

<span class="sd">        Unwraps :class:`~pysimm.system.Particle` images such that no bonds cross box edges.</span>

<span class="sd">        Args:</span>
<span class="sd">            None</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">check</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">add_particle_bonding</span><span class="p">()</span>
        <span class="n">next_to_unwrap</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="n">p</span><span class="o">.</span><span class="n">unwrapped</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="k">for</span> <span class="n">m</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">molecules</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">p0</span> <span class="ow">in</span> <span class="n">m</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
                <span class="n">p0</span><span class="o">.</span><span class="n">unwrapped</span> <span class="o">=</span> <span class="bp">True</span>
                <span class="n">next_to_unwrap</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p0</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">next_to_unwrap</span><span class="p">:</span>
                    <span class="k">for</span> <span class="n">pb</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bonded_to</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">pb</span><span class="o">.</span><span class="n">unwrapped</span><span class="p">:</span>
                            <span class="k">continue</span>
                        <span class="n">next_to_unwrap</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pb</span><span class="p">)</span>
                        <span class="n">pb</span><span class="o">.</span><span class="n">unwrapped</span> <span class="o">=</span> <span class="bp">True</span>
                        <span class="n">dx</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">x</span> <span class="o">-</span> <span class="n">pb</span><span class="o">.</span><span class="n">x</span>
                        <span class="k">while</span> <span class="nb">abs</span><span class="p">(</span><span class="n">dx</span><span class="p">)</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dx</span> <span class="o">/</span> <span class="mi">2</span><span class="p">:</span>
                            <span class="k">if</span> <span class="n">dx</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                                <span class="n">pb</span><span class="o">.</span><span class="n">x</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dx</span>
                            <span class="k">else</span><span class="p">:</span>
                                <span class="n">pb</span><span class="o">.</span><span class="n">x</span> <span class="o">-=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dx</span>
                            <span class="n">dx</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">x</span> <span class="o">-</span> <span class="n">pb</span><span class="o">.</span><span class="n">x</span>
                        <span class="n">dy</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span> <span class="o">-</span> <span class="n">pb</span><span class="o">.</span><span class="n">y</span>
                        <span class="k">while</span> <span class="nb">abs</span><span class="p">(</span><span class="n">dy</span><span class="p">)</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dy</span> <span class="o">/</span> <span class="mi">2</span><span class="p">:</span>
                            <span class="k">if</span> <span class="n">dy</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                                <span class="n">pb</span><span class="o">.</span><span class="n">y</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dy</span>
                            <span class="k">else</span><span class="p">:</span>
                                <span class="n">pb</span><span class="o">.</span><span class="n">y</span> <span class="o">-=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dy</span>
                            <span class="n">dy</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span> <span class="o">-</span> <span class="n">pb</span><span class="o">.</span><span class="n">y</span>
                        <span class="n">dz</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">z</span> <span class="o">-</span> <span class="n">pb</span><span class="o">.</span><span class="n">z</span>
                        <span class="k">while</span> <span class="nb">abs</span><span class="p">(</span><span class="n">dz</span><span class="p">)</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dz</span> <span class="o">/</span> <span class="mi">2</span><span class="p">:</span>
                            <span class="k">if</span> <span class="n">dz</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                                <span class="n">pb</span><span class="o">.</span><span class="n">z</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dz</span>
                            <span class="k">else</span><span class="p">:</span>
                                <span class="n">pb</span><span class="o">.</span><span class="n">z</span> <span class="o">-=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dz</span>
                            <span class="n">dz</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">z</span> <span class="o">-</span> <span class="n">pb</span><span class="o">.</span><span class="n">z</span>

        <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">b</span><span class="o">.</span><span class="n">distance</span><span class="p">()</span> <span class="o">&gt;</span> <span class="mi">5</span><span class="p">:</span>
                <span class="k">print</span><span class="p">(</span><span class="s1">&#39;unwrap probably failed&#39;</span><span class="p">)</span>
                <span class="k">return</span> <span class="bp">False</span>

        <span class="k">return</span> <span class="bp">True</span></div>
        
<div class="viewcode-block" id="System.unite_atoms"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.unite_atoms">[docs]</a>    <span class="k">def</span> <span class="nf">unite_atoms</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="n">p</span><span class="o">.</span><span class="n">implicit_h</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">elem</span> <span class="o">!=</span> <span class="s1">&#39;C&#39;</span><span class="p">:</span>
                <span class="k">continue</span>
            <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bonds</span><span class="p">:</span>
                <span class="n">pb</span> <span class="o">=</span> <span class="n">b</span><span class="o">.</span><span class="n">a</span> <span class="k">if</span> <span class="n">b</span><span class="o">.</span><span class="n">b</span> <span class="ow">is</span> <span class="n">p</span> <span class="k">else</span> <span class="n">b</span><span class="o">.</span><span class="n">b</span>
                <span class="k">if</span> <span class="n">pb</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span><span class="s1">&#39;H&#39;</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">implicit_h</span> <span class="o">+=</span> <span class="mi">1</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">charge</span> <span class="o">+=</span> <span class="n">pb</span><span class="o">.</span><span class="n">charge</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">pb</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">update</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">remove_spare_bonding</span><span class="p">()</span></div>

<div class="viewcode-block" id="System.quality"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.quality">[docs]</a>    <span class="k">def</span> <span class="nf">quality</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tolerance</span><span class="o">=</span><span class="mf">0.1</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.quality</span>

<span class="sd">        Attemps to assess quality of :class:`~pysimm.system.System` based on bond lengths in unwrapped system.</span>

<span class="sd">        Args:</span>
<span class="sd">            tolerance: fractional value of equilibrium bond length that is acceptable</span>

<span class="sd">        Returns:</span>
<span class="sd">            number of bonds in system outside tolerance</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">unwrap</span><span class="p">()</span>
        <span class="n">bad_bonds</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">b</span><span class="o">.</span><span class="n">distance</span><span class="p">()</span> <span class="o">&gt;</span> <span class="n">b</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">r0</span><span class="o">*</span><span class="p">(</span><span class="mi">1</span><span class="o">+</span><span class="n">tolerance</span><span class="p">)</span> <span class="ow">or</span> <span class="n">b</span><span class="o">.</span><span class="n">distance</span><span class="p">()</span> <span class="o">&lt;</span> <span class="n">b</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">r0</span><span class="o">*</span><span class="p">(</span><span class="mi">1</span><span class="o">-</span><span class="n">tolerance</span><span class="p">):</span>
                <span class="n">bad_bonds</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> of </span><span class="si">%s</span><span class="s1"> bonds found to be outside of tolerance&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">bad_bonds</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">count</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wrap</span><span class="p">()</span></div>

<div class="viewcode-block" id="System.shift_to_origin"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.shift_to_origin">[docs]</a>    <span class="k">def</span> <span class="nf">shift_to_origin</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.shift_to_origin</span>

<span class="sd">        Shifts simulation box to begin at origin. i.e. xlo=ylo=zlo=0</span>

<span class="sd">        Args:</span>
<span class="sd">            None</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="n">p</span><span class="o">.</span><span class="n">x</span> <span class="o">-=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xlo</span>
            <span class="n">p</span><span class="o">.</span><span class="n">y</span> <span class="o">-=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">ylo</span>
            <span class="n">p</span><span class="o">.</span><span class="n">z</span> <span class="o">-=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zlo</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xhi</span> <span class="o">-=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xlo</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">yhi</span> <span class="o">-=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">ylo</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zhi</span> <span class="o">-=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zlo</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xlo</span> <span class="o">-=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xlo</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">ylo</span> <span class="o">-=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">ylo</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zlo</span> <span class="o">-=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zlo</span></div>

<div class="viewcode-block" id="System.set_charge"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.set_charge">[docs]</a>    <span class="k">def</span> <span class="nf">set_charge</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.set_charge</span>

<span class="sd">        Sets total charge of all :class:`~pysimm.system.Particle` objects in System.particles</span>

<span class="sd">        Args:</span>
<span class="sd">            None</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">charge</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">charge</span> <span class="o">+=</span> <span class="n">p</span><span class="o">.</span><span class="n">charge</span></div>

<div class="viewcode-block" id="System.zero_charge"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.zero_charge">[docs]</a>    <span class="k">def</span> <span class="nf">zero_charge</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.zero_charge</span>

<span class="sd">        Enforces total :class:`~pysimm.system.System` charge to be 0.0 by subtracting excess charge from last particle</span>

<span class="sd">        Args:</span>
<span class="sd">            None:</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">charge</span> <span class="o">=</span> <span class="mf">0.</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="n">charge</span> <span class="o">+=</span> <span class="n">p</span><span class="o">.</span><span class="n">charge</span>
        <span class="k">if</span> <span class="n">charge</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">p</span><span class="o">.</span><span class="n">charge</span> <span class="o">-=</span> <span class="n">charge</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_charge</span><span class="p">()</span></div>

<div class="viewcode-block" id="System.check_items"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.check_items">[docs]</a>    <span class="k">def</span> <span class="nf">check_items</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.check_items</span>

<span class="sd">        Checks particles, bonds, angles, dihedrals, impropers, and molecules containers and raises exception if the length of items in the container does not equal the count property</span>

<span class="sd">        Args:</span>
<span class="sd">            None:</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">)</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">count</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">PysimmError</span><span class="p">(</span><span class="s1">&#39;particles missing&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="p">)</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">count</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">PysimmError</span><span class="p">(</span><span class="s1">&#39;bonds missing&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">angles</span><span class="p">)</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">angles</span><span class="o">.</span><span class="n">count</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">PysimmError</span><span class="p">(</span><span class="s1">&#39;angles missing&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dihedrals</span><span class="p">)</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedrals</span><span class="o">.</span><span class="n">count</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">PysimmError</span><span class="p">(</span><span class="s1">&#39;dihedrals missing&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">impropers</span><span class="p">)</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">impropers</span><span class="o">.</span><span class="n">count</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">PysimmError</span><span class="p">(</span><span class="s1">&#39;impropers missing&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">molecules</span><span class="p">)</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">molecules</span><span class="o">.</span><span class="n">count</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">PysimmError</span><span class="p">(</span><span class="s1">&#39;molecules missing&#39;</span><span class="p">)</span></div>
            
<div class="viewcode-block" id="System.update_ff_types_from_ac"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.update_ff_types_from_ac">[docs]</a>    <span class="k">def</span> <span class="nf">update_ff_types_from_ac</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ff</span><span class="p">,</span> <span class="n">acname</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.update_ff_types_from_ac</span>

<span class="sd">        Updates :class:`~pysimm.system.ParticleType` objects in system using type names given in antechamber (ac) file. Retrieves type from System if possible, then searches force field provided by ff.</span>

<span class="sd">        Args:</span>
<span class="sd">            ff: forcefield to search for Type objects</span>
<span class="sd">            acname: ac filename containing type names</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s1">&#39;all&#39;</span><span class="p">)</span>
        <span class="k">with</span> <span class="nb">file</span><span class="p">(</span><span class="n">acname</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">line</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;ATOM&#39;</span><span class="p">):</span>
                    <span class="n">tag</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">])</span>
                    <span class="n">tname</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
                    <span class="n">s_pt</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">tname</span><span class="p">)</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">s_pt</span><span class="p">:</span>
                        <span class="n">s_pt</span> <span class="o">=</span> <span class="n">ff</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">tname</span><span class="p">)</span>
                        <span class="k">if</span> <span class="ow">not</span> <span class="n">s_pt</span><span class="p">:</span>
                            <span class="n">error_print</span><span class="p">(</span><span class="s1">&#39;cannot find type with name {}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">tname</span><span class="p">))</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">s_pt</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">copy</span><span class="p">())</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">tname</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span></div>
                    

<div class="viewcode-block" id="System.update_particle_types_from_forcefield"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.update_particle_types_from_forcefield">[docs]</a>    <span class="k">def</span> <span class="nf">update_particle_types_from_forcefield</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">f</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.update_types_from_forcefield</span>

<span class="sd">        Updates :class:`~pysimm.system.ParticleType` data from :class:`~pysimm.forcefield.Forcefield` object f based on :class:`~pysimm.system.ParticleType`.name</span>

<span class="sd">        Args:</span>
<span class="sd">            f: :class:`~pysimm.forcefield.Forcefield` object reference</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">pt</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="p">:</span>
            <span class="n">name_</span> <span class="o">=</span> <span class="n">pt</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;@&#39;</span><span class="p">)[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">linker</span> <span class="o">=</span> <span class="bp">False</span>
            <span class="k">if</span> <span class="n">pt</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s1">&#39;@&#39;</span><span class="p">)</span> <span class="o">&gt;=</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">linker</span> <span class="o">=</span> <span class="n">pt</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;@&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">pt_</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">name_</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">pt_</span><span class="p">:</span>
                <span class="n">new</span> <span class="o">=</span> <span class="n">pt_</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
                <span class="n">new</span><span class="o">.</span><span class="n">tag</span> <span class="o">=</span> <span class="n">pt</span><span class="o">.</span><span class="n">tag</span>
                <span class="k">if</span> <span class="n">linker</span><span class="p">:</span>
                    <span class="n">new</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">%s</span><span class="s1">@</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">linker</span><span class="p">,</span> <span class="n">new</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">pt</span><span class="o">.</span><span class="n">tag</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">new</span><span class="p">)</span></div>

<div class="viewcode-block" id="System.make_linker_types"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.make_linker_types">[docs]</a>    <span class="k">def</span> <span class="nf">make_linker_types</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.make_linker_types</span>

<span class="sd">        Identifies linker particles and creates duplicate :class:`~pysimm.system.ParticleType objects with new names.</span>
<span class="sd">        Identification is performed by :class:`~pysimm.system.Particle`.linker attribute.</span>
<span class="sd">        New :class:`~pysimm.system.ParticleType` name is prepended with [H or T]L@ to designate head or tail linker</span>

<span class="sd">        Args:</span>
<span class="sd">            None</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">linker</span> <span class="o">==</span> <span class="s1">&#39;head&#39;</span><span class="p">:</span>
                <span class="n">head_linker</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;HL@</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">head_linker</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">head_linker</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;HL@</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="p">)</span>
            <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">linker</span> <span class="o">==</span> <span class="s1">&#39;tail&#39;</span><span class="p">:</span>
                <span class="n">tail_linker</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;TL@</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">tail_linker</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">tail_linker</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;TL@</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="p">)</span>
            <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">linker</span><span class="p">:</span>
                <span class="n">linker</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;L@</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">linker</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">linker</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;L@</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="p">)</span></div>

<div class="viewcode-block" id="System.remove_linker_types"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.remove_linker_types">[docs]</a>    <span class="k">def</span> <span class="nf">remove_linker_types</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.remove_linker_types</span>

<span class="sd">        Reassigns :class:`~pysimm.system.Particle`.type references to original :class:`~pysimm.system.ParticleType` objects without linker prepend</span>

<span class="sd">        Args:</span>
<span class="sd">            None</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s1">&#39;@&#39;</span><span class="p">)</span> <span class="o">&gt;=</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">pt</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;@&#39;</span><span class="p">)[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
                <span class="k">if</span> <span class="n">pt</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">pt</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">print</span><span class="p">(</span><span class="s1">&#39;cannot find regular type for linker </span><span class="si">%s</span><span class="s1">&#39;</span>
                          <span class="o">%</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">)</span></div>
            
                          
<div class="viewcode-block" id="System.read_lammps_dump"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.read_lammps_dump">[docs]</a>    <span class="k">def</span> <span class="nf">read_lammps_dump</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">fname</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.read_lammps_dump</span>

<span class="sd">        Updates particle positions and box size from LAMMPS dump file.</span>
<span class="sd">        Assumes following format for each atom line:</span>
<span class="sd">     </span>
<span class="sd">        tag charge xcoord ycoord zcoord xvelocity yvelocity zvelocity</span>


<span class="sd">        Args:</span>
<span class="sd">            fname: LAMMPS dump file</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">nparticles</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">fname</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
            <span class="k">while</span> <span class="n">line</span><span class="p">:</span>
                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">())</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;NUMBER&#39;</span><span class="p">:</span>
                    <span class="n">nparticles</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">readline</span><span class="p">())</span>
                <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">())</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;BOX&#39;</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xlo</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xhi</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="nb">float</span><span class="p">,</span> <span class="n">f</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">())</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">ylo</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">yhi</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="nb">float</span><span class="p">,</span> <span class="n">f</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">())</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zlo</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zhi</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="nb">float</span><span class="p">,</span> <span class="n">f</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">())</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">set_volume</span><span class="p">()</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">set_density</span><span class="p">()</span>
                <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">())</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;ATOMS&#39;</span><span class="p">:</span>
                    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nparticles</span><span class="p">):</span>
                        <span class="n">tag</span><span class="p">,</span> <span class="n">q</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="n">vx</span><span class="p">,</span> <span class="n">vy</span><span class="p">,</span> <span class="n">vz</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="nb">float</span><span class="p">,</span> <span class="n">f</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">())</span>
                        <span class="n">tag</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">tag</span><span class="p">)</span>
                        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">tag</span><span class="p">]:</span>
                            <span class="n">p</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span>
                            <span class="n">p</span><span class="o">.</span><span class="n">charge</span> <span class="o">=</span> <span class="n">q</span>
                            <span class="n">p</span><span class="o">.</span><span class="n">x</span> <span class="o">=</span> <span class="n">x</span>
                            <span class="n">p</span><span class="o">.</span><span class="n">vx</span> <span class="o">=</span> <span class="n">vx</span>
                            <span class="n">p</span><span class="o">.</span><span class="n">y</span> <span class="o">=</span> <span class="n">y</span>
                            <span class="n">p</span><span class="o">.</span><span class="n">vy</span> <span class="o">=</span> <span class="n">vy</span>
                            <span class="n">p</span><span class="o">.</span><span class="n">z</span> <span class="o">=</span> <span class="n">z</span>
                            <span class="n">p</span><span class="o">.</span><span class="n">vz</span> <span class="o">=</span> <span class="n">vz</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span></div>

<div class="viewcode-block" id="System.read_lammpstrj"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.read_lammpstrj">[docs]</a>    <span class="k">def</span> <span class="nf">read_lammpstrj</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">trj</span><span class="p">,</span> <span class="n">frame</span><span class="o">=</span><span class="mi">1</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.read_lammpstrj</span>

<span class="sd">        Updates particle positions and box size from LAMMPS trajectory file at given frame.</span>
<span class="sd">        </span>
<span class="sd">        Assumes one of following formats for each atom line:</span>
<span class="sd">     </span>
<span class="sd">        tag xcoord ycoord zcoord</span>
<span class="sd">        </span>
<span class="sd">        OR</span>
<span class="sd">        </span>
<span class="sd">        tag type_id xcoord ycoord zcoord</span>
<span class="sd">        </span>
<span class="sd">        OR</span>
<span class="sd">        </span>
<span class="sd">        tag type_id xcoord ycoord zcoord ximage yimage zimage</span>

<span class="sd">        Args:</span>
<span class="sd">            trj: LAMMPS trajectory file</span>
<span class="sd">            frame: sequential frame number (not LAMMPS timestep) default=1</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">t_frame</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="n">nparticles</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="n">updated</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">trj</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
            <span class="k">while</span> <span class="n">line</span><span class="p">:</span>
                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">())</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;TIMESTEP&#39;</span><span class="p">:</span>
                    <span class="n">t_frame</span> <span class="o">+=</span> <span class="mi">1</span>
                <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">())</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;NUMBER&#39;</span><span class="p">:</span>
                    <span class="n">nparticles</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">readline</span><span class="p">())</span>
                <span class="k">elif</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">())</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;BOX&#39;</span> <span class="ow">and</span>
                      <span class="n">t_frame</span> <span class="o">==</span> <span class="n">frame</span><span class="p">):</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xlo</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xhi</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="nb">float</span><span class="p">,</span>
                                                     <span class="n">f</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">())</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">ylo</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">yhi</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="nb">float</span><span class="p">,</span>
                                                     <span class="n">f</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">())</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zlo</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zhi</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="nb">float</span><span class="p">,</span>
                                                     <span class="n">f</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">())</span>
                <span class="k">elif</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">())</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;ATOMS&#39;</span> <span class="ow">and</span>
                      <span class="n">t_frame</span> <span class="o">==</span> <span class="n">frame</span><span class="p">):</span>
                    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nparticles</span><span class="p">):</span>
                        <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">==</span> <span class="mi">4</span><span class="p">:</span>
                            <span class="n">id_</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="nb">float</span><span class="p">,</span> <span class="n">line</span><span class="p">)</span>
                        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">==</span> <span class="mi">5</span><span class="p">:</span>
                            <span class="n">id_</span><span class="p">,</span> <span class="n">type_</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="nb">float</span><span class="p">,</span> <span class="n">line</span><span class="p">)</span>
                        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">==</span> <span class="mi">7</span><span class="p">:</span>
                            <span class="n">id_</span><span class="p">,</span> <span class="n">type_</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="n">ix</span><span class="p">,</span> <span class="n">iy</span><span class="p">,</span> <span class="n">iz</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="nb">float</span><span class="p">,</span> <span class="n">line</span><span class="p">)</span>
                        <span class="k">else</span><span class="p">:</span>
                            <span class="n">error_print</span><span class="p">(</span><span class="s1">&#39;cannot understand lammpstrj formatting; exiting&#39;</span><span class="p">)</span>
                            <span class="k">return</span>
                        <span class="n">id_</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">id_</span><span class="p">)</span>
                        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">id_</span><span class="p">]:</span>
                            <span class="n">updated</span> <span class="o">+=</span> <span class="mi">1</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">id_</span><span class="p">]</span><span class="o">.</span><span class="n">x</span> <span class="o">=</span> <span class="n">x</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">id_</span><span class="p">]</span><span class="o">.</span><span class="n">y</span> <span class="o">=</span> <span class="n">y</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">id_</span><span class="p">]</span><span class="o">.</span><span class="n">z</span> <span class="o">=</span> <span class="n">z</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>

        <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;updated particle positions for </span><span class="si">%s</span><span class="s1"> of </span><span class="si">%s</span><span class="s1"> particles from trajectory&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">updated</span><span class="p">,</span> <span class="n">nparticles</span><span class="p">))</span></div>

<div class="viewcode-block" id="System.read_xyz"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.read_xyz">[docs]</a>    <span class="k">def</span> <span class="nf">read_xyz</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">xyz</span><span class="p">,</span> <span class="n">frame</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">quiet</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.read_xyz</span>

<span class="sd">        Updates particle positions and box size from xyz file at given frame</span>

<span class="sd">        Args:</span>
<span class="sd">            xyz: xyz trajectory file</span>
<span class="sd">            frame: sequential frame number default=1</span>
<span class="sd">            quiet: True to print status default=False</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span><span class="p">:</span>
            <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;reading particle positions from </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">xyz</span><span class="p">)</span>
            <span class="n">warning_print</span><span class="p">(</span><span class="s1">&#39;particles are assumed to be in order in xyz file&#39;</span><span class="p">)</span>
        <span class="n">t_frame</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">xyz</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
            <span class="k">while</span> <span class="n">line</span><span class="p">:</span>
                <span class="n">t_frame</span> <span class="o">+=</span> <span class="mi">1</span>
                <span class="k">assert</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">0</span><span class="p">])</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">count</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
                <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">count</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span>
                    <span class="n">p</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">n</span><span class="p">]</span>
                    <span class="k">if</span> <span class="n">t_frame</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
                        <span class="k">if</span> <span class="ow">not</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">elem</span> <span class="ow">and</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">:</span>
                            <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">!=</span> <span class="s1">&#39;l&#39;</span><span class="p">:</span>
                                <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">elem</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span>
                            <span class="k">else</span><span class="p">:</span>
                                <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">elem</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span>
                    <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
                    <span class="k">if</span> <span class="n">t_frame</span> <span class="o">==</span> <span class="n">frame</span><span class="p">:</span>
                        <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="nb">float</span><span class="p">,</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">:])</span>
                        <span class="n">p</span><span class="o">.</span><span class="n">x</span> <span class="o">=</span> <span class="n">x</span>
                        <span class="n">p</span><span class="o">.</span><span class="n">y</span> <span class="o">=</span> <span class="n">y</span>
                        <span class="n">p</span><span class="o">.</span><span class="n">z</span> <span class="o">=</span> <span class="n">z</span>
                <span class="k">if</span> <span class="n">t_frame</span> <span class="o">==</span> <span class="n">frame</span><span class="p">:</span>
                    <span class="k">print</span><span class="p">(</span><span class="s1">&#39;read </span><span class="si">%s</span><span class="s1"> particle positions from </span><span class="si">%s</span><span class="s1">&#39;</span>
                          <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">count</span><span class="p">,</span> <span class="n">xyz</span><span class="p">))</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span></div>

<div class="viewcode-block" id="System.update_types"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.update_types">[docs]</a>    <span class="k">def</span> <span class="nf">update_types</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ptypes</span><span class="p">,</span> <span class="n">btypes</span><span class="p">,</span> <span class="n">atypes</span><span class="p">,</span> <span class="n">dtypes</span><span class="p">,</span> <span class="n">itypes</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.update_types</span>

<span class="sd">        Updates type objects from a given list of types.</span>

<span class="sd">        Args:</span>
<span class="sd">            ptypes: list of :class:`~pysimm.system.ParticleType` objects from which to update</span>
<span class="sd">            btypes: list of :class:`~pysimm.system.BondType` objects from which to update</span>
<span class="sd">            atypes: list of :class:`~pysimm.system.AngleType` objects from which to update</span>
<span class="sd">            dtypes: list of :class:`~pysimm.system.DihedralType` objects from which to update</span>
<span class="sd">            itypes: list of :class:`~pysimm.system.ImproperType` objects from which to update</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">ptypes</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
                <span class="n">pt</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">first</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">pt</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">pt</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s1">&#39;all&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">pt</span> <span class="ow">in</span> <span class="n">ptypes</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">pt</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">btypes</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="p">:</span>
                <span class="n">bt</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bond_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">first</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">bt</span><span class="p">:</span>
                    <span class="n">b</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">bt</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">bond_types</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s1">&#39;all&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">bt</span> <span class="ow">in</span> <span class="n">btypes</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">bond_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">bt</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">atypes</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">angles</span><span class="p">:</span>
                <span class="n">at</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">first</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">at</span><span class="p">:</span>
                    <span class="n">a</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">at</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s1">&#39;all&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">at</span> <span class="ow">in</span> <span class="n">atypes</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">at</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">dtypes</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedrals</span><span class="p">:</span>
                <span class="n">dt</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">first</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">dt</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">dt</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s1">&#39;all&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">dt</span> <span class="ow">in</span> <span class="n">dtypes</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">dt</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">itypes</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">impropers</span><span class="p">:</span>
                <span class="n">it</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">i</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">first</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">it</span><span class="p">:</span>
                    <span class="n">i</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">it</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s1">&#39;all&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">it</span> <span class="ow">in</span> <span class="n">itypes</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">it</span><span class="p">)</span></div>

<div class="viewcode-block" id="System.read_type_names"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.read_type_names">[docs]</a>    <span class="k">def</span> <span class="nf">read_type_names</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">types_file</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.read_type_names</span>

<span class="sd">        Update :class:`~pysimm.system.ParticleType` names from file.</span>

<span class="sd">        Args:</span>
<span class="sd">            types_file: type dictionary file name</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">ptypes</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
        <span class="n">btypes</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
        <span class="n">atypes</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
        <span class="n">dtypes</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
        <span class="n">itypes</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>

        <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="n">types_file</span><span class="p">):</span>
            <span class="n">f</span> <span class="o">=</span> <span class="nb">file</span><span class="p">(</span><span class="n">types_file</span><span class="p">)</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">types_file</span><span class="p">,</span> <span class="nb">basestring</span><span class="p">):</span>
            <span class="n">f</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">(</span><span class="n">types_file</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">line</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
            <span class="k">if</span> <span class="n">line</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;atom&#39;</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">count</span><span class="p">):</span>
                    <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                    <span class="n">ptypes</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])]</span> <span class="o">=</span> <span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
            <span class="k">elif</span> <span class="n">line</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;bond&#39;</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bond_types</span><span class="o">.</span><span class="n">count</span><span class="p">):</span>
                    <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                    <span class="n">btypes</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])]</span> <span class="o">=</span> <span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
            <span class="k">elif</span> <span class="n">line</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;angle&#39;</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">count</span><span class="p">):</span>
                    <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                    <span class="n">atypes</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])]</span> <span class="o">=</span> <span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
            <span class="k">elif</span> <span class="n">line</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;dihedral&#39;</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">count</span><span class="p">):</span>
                    <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                    <span class="n">dtypes</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])]</span> <span class="o">=</span> <span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
            <span class="k">elif</span> <span class="n">line</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;improper&#39;</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">count</span><span class="p">):</span>
                    <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                    <span class="n">itypes</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])]</span> <span class="o">=</span> <span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>

        <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="p">:</span>
            <span class="n">t</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">ptypes</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">tag</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">t</span><span class="o">.</span><span class="n">name</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;L&#39;</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">t</span><span class="o">.</span><span class="n">name</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;H&#39;</span><span class="p">,</span> <span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;N&#39;</span><span class="p">,</span> <span class="s1">&#39;O&#39;</span><span class="p">]:</span>
                    <span class="n">t</span><span class="o">.</span><span class="n">elem</span> <span class="o">=</span> <span class="n">t</span><span class="o">.</span><span class="n">name</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">t</span><span class="o">.</span><span class="n">name</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;H&#39;</span><span class="p">,</span> <span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;N&#39;</span><span class="p">,</span> <span class="s1">&#39;O&#39;</span><span class="p">]:</span>
                    <span class="n">t</span><span class="o">.</span><span class="n">elem</span> <span class="o">=</span> <span class="n">t</span><span class="o">.</span><span class="n">name</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bond_types</span><span class="p">:</span>
            <span class="n">t</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">btypes</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">tag</span><span class="p">]</span>
            <span class="n">t</span><span class="o">.</span><span class="n">rname</span> <span class="o">=</span> <span class="s1">&#39;,&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">reversed</span><span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;,&#39;</span><span class="p">)))</span>
        <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="p">:</span>
            <span class="n">t</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">atypes</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">tag</span><span class="p">]</span>
            <span class="n">t</span><span class="o">.</span><span class="n">rname</span> <span class="o">=</span> <span class="s1">&#39;,&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">reversed</span><span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;,&#39;</span><span class="p">)))</span>
        <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">:</span>
            <span class="n">t</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">dtypes</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">tag</span><span class="p">]</span>
            <span class="n">t</span><span class="o">.</span><span class="n">rname</span> <span class="o">=</span> <span class="s1">&#39;,&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">reversed</span><span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;,&#39;</span><span class="p">)))</span>
        <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="p">:</span>
            <span class="n">t</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">itypes</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">tag</span><span class="p">]</span>
            <span class="n">t</span><span class="o">.</span><span class="n">rname</span> <span class="o">=</span> <span class="s1">&#39;,&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">reversed</span><span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;,&#39;</span><span class="p">)))</span></div>

<div class="viewcode-block" id="System.remove_spare_bonding"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.remove_spare_bonding">[docs]</a>    <span class="k">def</span> <span class="nf">remove_spare_bonding</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">update_tags</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.remove_spare_bonding</span>

<span class="sd">        Removes bonds, angles, dihedrals and impropers that reference particles not in :class:`~pysimm.system.System`.particles</span>

<span class="sd">        Args:</span>
<span class="sd">            update_tags: True to update all tags after removal of bonding items default=True</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">b</span><span class="o">.</span><span class="n">a</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span> <span class="ow">or</span> <span class="n">b</span><span class="o">.</span><span class="n">b</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">update</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">angles</span><span class="p">:</span>
            <span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">a</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span> <span class="ow">or</span> <span class="n">a</span><span class="o">.</span><span class="n">b</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span> <span class="ow">or</span>
                    <span class="n">a</span><span class="o">.</span><span class="n">c</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">angles</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">update</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedrals</span><span class="p">:</span>
            <span class="k">if</span> <span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">a</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span> <span class="ow">or</span> <span class="n">d</span><span class="o">.</span><span class="n">b</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span> <span class="ow">or</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">c</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span> <span class="ow">or</span> <span class="n">d</span><span class="o">.</span><span class="n">d</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">dihedrals</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">update</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">impropers</span><span class="p">:</span>
            <span class="k">if</span> <span class="p">(</span><span class="n">i</span><span class="o">.</span><span class="n">a</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span> <span class="ow">or</span> <span class="n">i</span><span class="o">.</span><span class="n">b</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span> <span class="ow">or</span>
                    <span class="n">i</span><span class="o">.</span><span class="n">c</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span> <span class="ow">or</span> <span class="n">i</span><span class="o">.</span><span class="n">d</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">impropers</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">i</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">update</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">update_tags</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">update_tags</span><span class="p">()</span></div>

<div class="viewcode-block" id="System.update_tags"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.update_tags">[docs]</a>    <span class="k">def</span> <span class="nf">update_tags</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.update_tags</span>

<span class="sd">        Update Item tags in :class:`~pysimm.utils.ItemContainer` objects to preserve continuous tags. Removes all objects and then reinserts them.</span>

<span class="sd">         Args:</span>
<span class="sd">             None</span>

<span class="sd">         Returns:</span>
<span class="sd">             None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">particles</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;all&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s1">&#39;all&#39;</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">particles</span><span class="p">:</span>
            <span class="k">del</span> <span class="n">p</span><span class="o">.</span><span class="n">tag</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>

        <span class="n">ptypes</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;all&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s1">&#39;all&#39;</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">pt</span> <span class="ow">in</span> <span class="n">ptypes</span><span class="p">:</span>
            <span class="k">del</span> <span class="n">pt</span><span class="o">.</span><span class="n">tag</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">pt</span><span class="p">)</span>

        <span class="n">bonds</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;all&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s1">&#39;all&#39;</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="n">bonds</span><span class="p">:</span>
            <span class="k">del</span> <span class="n">b</span><span class="o">.</span><span class="n">tag</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">b</span><span class="p">)</span>

        <span class="n">btypes</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bond_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;all&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bond_types</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s1">&#39;all&#39;</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">bt</span> <span class="ow">in</span> <span class="n">btypes</span><span class="p">:</span>
            <span class="k">del</span> <span class="n">bt</span><span class="o">.</span><span class="n">tag</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">bond_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">bt</span><span class="p">)</span>

        <span class="n">angles</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">angles</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;all&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">angles</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s1">&#39;all&#39;</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="n">angles</span><span class="p">:</span>
            <span class="k">del</span> <span class="n">a</span><span class="o">.</span><span class="n">tag</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">angles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>

        <span class="n">atypes</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;all&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s1">&#39;all&#39;</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">at</span> <span class="ow">in</span> <span class="n">atypes</span><span class="p">:</span>
            <span class="k">del</span> <span class="n">at</span><span class="o">.</span><span class="n">tag</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">at</span><span class="p">)</span>

        <span class="n">dihedrals</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedrals</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;all&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dihedrals</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s1">&#39;all&#39;</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">dihedrals</span><span class="p">:</span>
            <span class="k">del</span> <span class="n">d</span><span class="o">.</span><span class="n">tag</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">dihedrals</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>

        <span class="n">dtypes</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;all&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s1">&#39;all&#39;</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">dt</span> <span class="ow">in</span> <span class="n">dtypes</span><span class="p">:</span>
            <span class="k">del</span> <span class="n">dt</span><span class="o">.</span><span class="n">tag</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">dt</span><span class="p">)</span>

        <span class="n">impropers</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">impropers</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;all&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">impropers</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s1">&#39;all&#39;</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">impropers</span><span class="p">:</span>
            <span class="k">del</span> <span class="n">i</span><span class="o">.</span><span class="n">tag</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">impropers</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>

        <span class="n">itypes</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;all&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s1">&#39;all&#39;</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">it</span> <span class="ow">in</span> <span class="n">itypes</span><span class="p">:</span>
            <span class="k">del</span> <span class="n">it</span><span class="o">.</span><span class="n">tag</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">it</span><span class="p">)</span></div>

<div class="viewcode-block" id="System.set_references"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.set_references">[docs]</a>    <span class="k">def</span> <span class="nf">set_references</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.set_references</span>

<span class="sd">        Set object references when :class:`~pysimm.system.System` information read from text file.</span>
<span class="sd">        For example, if bond type value 2 is read from file, set :class:`~pysimm.system.Bond`.type to bond_types[2]</span>

<span class="sd">        Args:</span>
<span class="sd">            None</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="nb">int</span><span class="p">)</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="p">[</span><span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="p">]:</span>
                <span class="n">p</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="p">[</span><span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="p">]</span>
            <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="nb">int</span><span class="p">)</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="p">[</span><span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="p">]:</span>
                <span class="n">error_print</span><span class="p">(</span><span class="s1">&#39;error: Cannot find type with tag </span><span class="si">%s</span><span class="s1"> in system &#39;</span>
                            <span class="s1">&#39;particles types&#39;</span> <span class="o">%</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="nb">int</span><span class="p">)</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">bond_types</span><span class="p">[</span><span class="n">b</span><span class="o">.</span><span class="n">type</span><span class="p">]:</span>
                <span class="n">b</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bond_types</span><span class="p">[</span><span class="n">b</span><span class="o">.</span><span class="n">type</span><span class="p">]</span>
            <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="nb">int</span><span class="p">)</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bond_types</span><span class="p">[</span><span class="n">b</span><span class="o">.</span><span class="n">type</span><span class="p">]:</span>
                <span class="n">error_print</span><span class="p">(</span><span class="s1">&#39;error: Cannot find type with tag </span><span class="si">%s</span><span class="s1"> in system &#39;</span>
                            <span class="s1">&#39;bond types&#39;</span> <span class="o">%</span> <span class="n">b</span><span class="o">.</span><span class="n">type</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">angles</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="nb">int</span><span class="p">)</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="p">[</span><span class="n">a</span><span class="o">.</span><span class="n">type</span><span class="p">]:</span>
                <span class="n">a</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="p">[</span><span class="n">a</span><span class="o">.</span><span class="n">type</span><span class="p">]</span>
            <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="nb">int</span><span class="p">)</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="p">[</span><span class="n">a</span><span class="o">.</span><span class="n">type</span><span class="p">]:</span>
                <span class="n">error_print</span><span class="p">(</span><span class="s1">&#39;error: Cannot find type with tag </span><span class="si">%s</span><span class="s1"> in system &#39;</span>
                            <span class="s1">&#39;angle types&#39;</span> <span class="o">%</span> <span class="n">a</span><span class="o">.</span><span class="n">type</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedrals</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="nb">int</span><span class="p">)</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">[</span><span class="n">d</span><span class="o">.</span><span class="n">type</span><span class="p">]:</span>
                <span class="n">d</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">[</span><span class="n">d</span><span class="o">.</span><span class="n">type</span><span class="p">]</span>
            <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="nb">int</span><span class="p">)</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">[</span><span class="n">d</span><span class="o">.</span><span class="n">type</span><span class="p">]:</span>
                <span class="n">error_print</span><span class="p">(</span><span class="s1">&#39;error: Cannot find type with tag </span><span class="si">%s</span><span class="s1"> in system &#39;</span>
                            <span class="s1">&#39;dihedral types&#39;</span> <span class="o">%</span> <span class="n">d</span><span class="o">.</span><span class="n">type</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">impropers</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">i</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="nb">int</span><span class="p">)</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="p">[</span><span class="n">i</span><span class="o">.</span><span class="n">type</span><span class="p">]:</span>
                <span class="n">i</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="p">[</span><span class="n">i</span><span class="o">.</span><span class="n">type</span><span class="p">]</span>
            <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">i</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="nb">int</span><span class="p">)</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="p">[</span><span class="n">i</span><span class="o">.</span><span class="n">type</span><span class="p">]:</span>
                <span class="n">error_print</span><span class="p">(</span><span class="s1">&#39;error: Cannot find type with tag </span><span class="si">%s</span><span class="s1"> in system &#39;</span>
                            <span class="s1">&#39;improper types&#39;</span> <span class="o">%</span> <span class="n">i</span><span class="o">.</span><span class="n">type</span><span class="p">)</span></div>

<div class="viewcode-block" id="System.objectify"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.objectify">[docs]</a>    <span class="k">def</span> <span class="nf">objectify</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.objectify</span>

<span class="sd">        Set references for :class:`~pysimm.system.Bond`, :class:`~pysimm.system.Angle`, :class:`~pysimm.system.Dihedral`, :class:`~pysimm.system.Improper` objects.</span>
<span class="sd">        For example, if read from file that bond #1 is between particle 1 and 2 set :class:`~pysimm.system.Bond`.a to particles[1], etc.</span>

<span class="sd">        Args:</span>
<span class="sd">            None</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">objectified</span><span class="p">:</span>
            <span class="k">return</span> <span class="s1">&#39;already objectified&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_references</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">molecule</span><span class="p">,</span> <span class="n">Molecule</span><span class="p">):</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">molecules</span><span class="p">[</span><span class="n">p</span><span class="o">.</span><span class="n">molecule</span><span class="p">]:</span>
                    <span class="n">m</span> <span class="o">=</span> <span class="n">Molecule</span><span class="p">()</span>
                    <span class="n">m</span><span class="o">.</span><span class="n">tag</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">molecule</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">molecules</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
                <span class="n">p</span><span class="o">.</span><span class="n">molecule</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">molecules</span><span class="p">[</span><span class="n">p</span><span class="o">.</span><span class="n">molecule</span><span class="p">]</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">molecules</span><span class="p">[</span><span class="n">p</span><span class="o">.</span><span class="n">molecule</span><span class="o">.</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
            <span class="n">p</span><span class="o">.</span><span class="n">bonds</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>
            <span class="n">p</span><span class="o">.</span><span class="n">angles</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>
            <span class="n">p</span><span class="o">.</span><span class="n">dihedrals</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>
            <span class="n">p</span><span class="o">.</span><span class="n">impropers</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">a</span><span class="p">)</span> <span class="o">==</span> <span class="nb">int</span><span class="p">:</span>
                <span class="n">b</span><span class="o">.</span><span class="n">a</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">b</span><span class="o">.</span><span class="n">a</span><span class="p">]</span>
                <span class="n">b</span><span class="o">.</span><span class="n">b</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">b</span><span class="o">.</span><span class="n">b</span><span class="p">]</span>
                <span class="n">b</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">b</span><span class="p">)</span>
                <span class="n">b</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">b</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">b</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">molecule</span><span class="p">:</span>
                    <span class="n">b</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">molecule</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">b</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">angles</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">a</span><span class="p">)</span> <span class="o">==</span> <span class="nb">int</span><span class="p">:</span>
                <span class="n">a</span><span class="o">.</span><span class="n">a</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">a</span><span class="o">.</span><span class="n">a</span><span class="p">]</span>
                <span class="n">a</span><span class="o">.</span><span class="n">b</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">a</span><span class="o">.</span><span class="n">b</span><span class="p">]</span>
                <span class="n">a</span><span class="o">.</span><span class="n">c</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">a</span><span class="o">.</span><span class="n">c</span><span class="p">]</span>
                <span class="k">if</span> <span class="n">a</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">molecule</span><span class="p">:</span>
                    <span class="n">a</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">molecule</span><span class="o">.</span><span class="n">angles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedrals</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">a</span><span class="p">)</span> <span class="o">==</span> <span class="nb">int</span><span class="p">:</span>
                <span class="n">d</span><span class="o">.</span><span class="n">a</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">d</span><span class="o">.</span><span class="n">a</span><span class="p">]</span>
                <span class="n">d</span><span class="o">.</span><span class="n">b</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">d</span><span class="o">.</span><span class="n">b</span><span class="p">]</span>
                <span class="n">d</span><span class="o">.</span><span class="n">c</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">d</span><span class="o">.</span><span class="n">c</span><span class="p">]</span>
                <span class="n">d</span><span class="o">.</span><span class="n">d</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">d</span><span class="o">.</span><span class="n">d</span><span class="p">]</span>
                <span class="k">if</span> <span class="n">d</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">molecule</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">molecule</span><span class="o">.</span><span class="n">dihedrals</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">impropers</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">i</span><span class="o">.</span><span class="n">a</span><span class="p">)</span> <span class="o">==</span> <span class="nb">int</span><span class="p">:</span>
                <span class="n">i</span><span class="o">.</span><span class="n">a</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="o">.</span><span class="n">a</span><span class="p">]</span>
                <span class="n">i</span><span class="o">.</span><span class="n">b</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="o">.</span><span class="n">b</span><span class="p">]</span>
                <span class="n">i</span><span class="o">.</span><span class="n">c</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="o">.</span><span class="n">c</span><span class="p">]</span>
                <span class="n">i</span><span class="o">.</span><span class="n">d</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="o">.</span><span class="n">d</span><span class="p">]</span>
                <span class="k">if</span> <span class="n">i</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">molecule</span><span class="p">:</span>
                    <span class="n">i</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">molecule</span><span class="o">.</span><span class="n">impropers</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">objectified</span> <span class="o">=</span> <span class="bp">True</span></div>

<div class="viewcode-block" id="System.add_particle_bonding"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.add_particle_bonding">[docs]</a>    <span class="k">def</span> <span class="nf">add_particle_bonding</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.add_particle_bonding</span>

<span class="sd">        Update :class:`~pysimm.system.Particle` objects such that :class:`~pysimm.system.Particle`.bonded_to contains other :class:`~pysimm.system.Particle` objects invloved in bonding</span>

<span class="sd">        Args:</span>
<span class="sd">            None</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="n">p</span><span class="o">.</span><span class="n">bonded_to</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>
            <span class="n">p</span><span class="o">.</span><span class="n">bonds</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="p">:</span>
            <span class="n">b</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">bonded_to</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">b</span><span class="p">)</span>
            <span class="n">b</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">b</span><span class="p">)</span>
            <span class="n">b</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">bonded_to</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">a</span><span class="p">)</span>
            <span class="n">b</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">b</span><span class="p">)</span></div>

<div class="viewcode-block" id="System.set_excluded_particles"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.set_excluded_particles">[docs]</a>    <span class="k">def</span> <span class="nf">set_excluded_particles</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">bonds</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">angles</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">dihedrals</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.set_excluded_particles</span>

<span class="sd">        Updates :class:`~pysimm.system.Particle` object such that :class:`~pysimm.system.Particle`.excluded_particles contains other :class:`~pysimm.system.Particle` objects involved in</span>
<span class="sd">        1-2, 1-3, and/or 1-4 interactions</span>

<span class="sd">        Args:</span>
<span class="sd">            bonds: exclude particles involved in 1-2 interactions</span>
<span class="sd">            angles: exclude particles involved in 1-3 interactions</span>
<span class="sd">            dihedrals: exclude particles involved in 1-4 interactions</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="n">p</span><span class="o">.</span><span class="n">excluded_particles</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>

        <span class="k">if</span> <span class="n">bonds</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">b</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span> <span class="o">&lt;</span> <span class="n">b</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">:</span>
                    <span class="n">b</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">excluded_particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">b</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">b</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">excluded_particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">a</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">angles</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">angles</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">a</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span> <span class="o">&lt;</span> <span class="n">a</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">:</span>
                    <span class="n">a</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">excluded_particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">b</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">a</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span> <span class="o">&lt;</span> <span class="n">a</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">tag</span><span class="p">:</span>
                    <span class="n">a</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">excluded_particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">c</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">a</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span> <span class="o">&lt;</span> <span class="n">a</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">:</span>
                    <span class="n">a</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">excluded_particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">a</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">a</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span> <span class="o">&lt;</span> <span class="n">a</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">tag</span><span class="p">:</span>
                    <span class="n">a</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">excluded_particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">c</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">a</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">tag</span> <span class="o">&lt;</span> <span class="n">a</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">:</span>
                    <span class="n">a</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">excluded_particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">a</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">a</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">tag</span> <span class="o">&lt;</span> <span class="n">a</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">:</span>
                    <span class="n">a</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">excluded_particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">b</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">dihedrals</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedrals</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">d</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span> <span class="o">&lt;</span> <span class="n">d</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">excluded_particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">b</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">d</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span> <span class="o">&lt;</span> <span class="n">d</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">tag</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">excluded_particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">c</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">d</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span> <span class="o">&lt;</span> <span class="n">d</span><span class="o">.</span><span class="n">d</span><span class="o">.</span><span class="n">tag</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">excluded_particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">d</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">d</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span> <span class="o">&lt;</span> <span class="n">d</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">excluded_particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">a</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">d</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span> <span class="o">&lt;</span> <span class="n">d</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">tag</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">excluded_particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">c</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">d</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span> <span class="o">&lt;</span> <span class="n">d</span><span class="o">.</span><span class="n">d</span><span class="o">.</span><span class="n">tag</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">excluded_particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">d</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">d</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">tag</span> <span class="o">&lt;</span> <span class="n">d</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">excluded_particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">a</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">d</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">tag</span> <span class="o">&lt;</span> <span class="n">d</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">excluded_particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">b</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">d</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">tag</span> <span class="o">&lt;</span> <span class="n">d</span><span class="o">.</span><span class="n">d</span><span class="o">.</span><span class="n">tag</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">excluded_particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">d</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">d</span><span class="o">.</span><span class="n">d</span><span class="o">.</span><span class="n">tag</span> <span class="o">&lt;</span> <span class="n">d</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">d</span><span class="o">.</span><span class="n">excluded_particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">a</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">d</span><span class="o">.</span><span class="n">d</span><span class="o">.</span><span class="n">tag</span> <span class="o">&lt;</span> <span class="n">d</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">d</span><span class="o">.</span><span class="n">excluded_particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">b</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">d</span><span class="o">.</span><span class="n">d</span><span class="o">.</span><span class="n">tag</span> <span class="o">&lt;</span> <span class="n">d</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">tag</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">d</span><span class="o">.</span><span class="n">excluded_particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">c</span><span class="p">)</span></div>

<div class="viewcode-block" id="System.set_atomic_numbers"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.set_atomic_numbers">[docs]</a>    <span class="k">def</span> <span class="nf">set_atomic_numbers</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.set_atomic_numbers</span>

<span class="sd">        Updates :class:`~pysimm.system.ParticleType` objects with atomic number based on :class:`~pysimm.system.ParticleType`.elem</span>

<span class="sd">        Args:</span>
<span class="sd">            None</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">pt</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">pt</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;H&#39;</span><span class="p">:</span>
                <span class="n">pt</span><span class="o">.</span><span class="n">atomic_number</span> <span class="o">=</span> <span class="mi">1</span>
            <span class="k">elif</span> <span class="n">pt</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;He&#39;</span><span class="p">:</span>
                <span class="n">pt</span><span class="o">.</span><span class="n">atomic_number</span> <span class="o">=</span> <span class="mi">2</span>
            <span class="k">elif</span> <span class="n">pt</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;Li&#39;</span><span class="p">:</span>
                <span class="n">pt</span><span class="o">.</span><span class="n">atomic_number</span> <span class="o">=</span> <span class="mi">3</span>
            <span class="k">elif</span> <span class="n">pt</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;Be&#39;</span><span class="p">:</span>
                <span class="n">pt</span><span class="o">.</span><span class="n">atomic_number</span> <span class="o">=</span> <span class="mi">4</span>
            <span class="k">elif</span> <span class="n">pt</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;B&#39;</span><span class="p">:</span>
                <span class="n">pt</span><span class="o">.</span><span class="n">atomic_number</span> <span class="o">=</span> <span class="mi">5</span>
            <span class="k">elif</span> <span class="n">pt</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;C&#39;</span><span class="p">:</span>
                <span class="n">pt</span><span class="o">.</span><span class="n">atomic_number</span> <span class="o">=</span> <span class="mi">6</span>
            <span class="k">elif</span> <span class="n">pt</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;N&#39;</span><span class="p">:</span>
                <span class="n">pt</span><span class="o">.</span><span class="n">atomic_number</span> <span class="o">=</span> <span class="mi">7</span>
            <span class="k">elif</span> <span class="n">pt</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;O&#39;</span><span class="p">:</span>
                <span class="n">pt</span><span class="o">.</span><span class="n">atomic_number</span> <span class="o">=</span> <span class="mi">8</span>
            <span class="k">elif</span> <span class="n">pt</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;F&#39;</span><span class="p">:</span>
                <span class="n">pt</span><span class="o">.</span><span class="n">atomic_number</span> <span class="o">=</span> <span class="mi">9</span>
            <span class="k">elif</span> <span class="n">pt</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;Ne&#39;</span><span class="p">:</span>
                <span class="n">pt</span><span class="o">.</span><span class="n">atomic_number</span> <span class="o">=</span> <span class="mi">10</span>
            <span class="k">elif</span> <span class="n">pt</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;Na&#39;</span><span class="p">:</span>
                <span class="n">pt</span><span class="o">.</span><span class="n">atomic_number</span> <span class="o">=</span> <span class="mi">11</span>
            <span class="k">elif</span> <span class="n">pt</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;Mg&#39;</span><span class="p">:</span>
                <span class="n">pt</span><span class="o">.</span><span class="n">atomic_number</span> <span class="o">=</span> <span class="mi">12</span>
            <span class="k">elif</span> <span class="n">pt</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;Al&#39;</span><span class="p">:</span>
                <span class="n">pt</span><span class="o">.</span><span class="n">atomic_number</span> <span class="o">=</span> <span class="mi">13</span>
            <span class="k">elif</span> <span class="n">pt</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;Si&#39;</span><span class="p">:</span>
                <span class="n">pt</span><span class="o">.</span><span class="n">atomic_number</span> <span class="o">=</span> <span class="mi">14</span>
            <span class="k">elif</span> <span class="n">pt</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;P&#39;</span><span class="p">:</span>
                <span class="n">pt</span><span class="o">.</span><span class="n">atomic_number</span> <span class="o">=</span> <span class="mi">15</span>
            <span class="k">elif</span> <span class="n">pt</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;S&#39;</span><span class="p">:</span>
                <span class="n">pt</span><span class="o">.</span><span class="n">atomic_number</span> <span class="o">=</span> <span class="mi">16</span>
            <span class="k">elif</span> <span class="n">pt</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;Cl&#39;</span><span class="p">:</span>
                <span class="n">pt</span><span class="o">.</span><span class="n">atomic_number</span> <span class="o">=</span> <span class="mi">17</span>
            <span class="k">elif</span> <span class="n">pt</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;Ar&#39;</span><span class="p">:</span>
                <span class="n">pt</span><span class="o">.</span><span class="n">atomic_number</span> <span class="o">=</span> <span class="mi">18</span>
            <span class="k">elif</span> <span class="n">pt</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;K&#39;</span><span class="p">:</span>
                <span class="n">pt</span><span class="o">.</span><span class="n">atomic_number</span> <span class="o">=</span> <span class="mi">19</span>
            <span class="k">elif</span> <span class="n">pt</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;Ca&#39;</span><span class="p">:</span>
                <span class="n">pt</span><span class="o">.</span><span class="n">atomic_number</span> <span class="o">=</span> <span class="mi">20</span>
            <span class="k">elif</span> <span class="n">pt</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;Br&#39;</span><span class="p">:</span>
                <span class="n">pt</span><span class="o">.</span><span class="n">atomic_number</span> <span class="o">=</span> <span class="mi">35</span>
            <span class="k">elif</span> <span class="n">pt</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;I&#39;</span><span class="p">:</span>
                <span class="n">pt</span><span class="o">.</span><span class="n">atomic_number</span> <span class="o">=</span> <span class="mi">53</span></div>

<div class="viewcode-block" id="System.add_particle_bonded_to"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.add_particle_bonded_to">[docs]</a>    <span class="k">def</span> <span class="nf">add_particle_bonded_to</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">p0</span><span class="p">,</span> <span class="n">f</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">sep</span><span class="o">=</span><span class="mf">1.5</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.add_particle_bonded_to</span>

<span class="sd">        Add new :class:`~pysimm.system.Particle` to :class:`~pysimm.system.System` bonded to p0 and automatically update new forcefield types</span>

<span class="sd">        Args:</span>
<span class="sd">            p: new :class:`~pysimm.system.Particle` object to be added</span>
<span class="sd">            p0: original :class:`~pysimm.system.Particle` object in :class:`~pysimm.system.System` to which p will be bonded</span>
<span class="sd">            f: :class:`~pysimm.forcefield.Forcefield` object from which new force field types will be retrieved</span>

<span class="sd">        Returns:</span>
<span class="sd">            new Particle being added to system for convenient reference</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">x</span> <span class="ow">is</span> <span class="bp">None</span> <span class="ow">or</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span> <span class="ow">is</span> <span class="bp">None</span> <span class="ow">or</span> <span class="n">p</span><span class="o">.</span><span class="n">z</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">phi</span> <span class="o">=</span> <span class="n">random</span><span class="p">()</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">pi</span>
            <span class="n">theta</span> <span class="o">=</span> <span class="n">acos</span><span class="p">(</span><span class="n">random</span><span class="p">()</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span>
            <span class="n">p</span><span class="o">.</span><span class="n">x</span> <span class="o">=</span> <span class="n">p0</span><span class="o">.</span><span class="n">x</span> <span class="o">+</span> <span class="n">sep</span> <span class="o">*</span> <span class="n">cos</span><span class="p">(</span><span class="n">theta</span><span class="p">)</span> <span class="o">*</span> <span class="n">sin</span><span class="p">(</span><span class="n">phi</span><span class="p">)</span>
            <span class="n">p</span><span class="o">.</span><span class="n">y</span> <span class="o">=</span> <span class="n">p0</span><span class="o">.</span><span class="n">y</span> <span class="o">+</span> <span class="n">sep</span> <span class="o">*</span> <span class="n">sin</span><span class="p">(</span><span class="n">theta</span><span class="p">)</span> <span class="o">*</span> <span class="n">sin</span><span class="p">(</span><span class="n">phi</span><span class="p">)</span>
            <span class="n">p</span><span class="o">.</span><span class="n">z</span> <span class="o">=</span> <span class="n">p0</span><span class="o">.</span><span class="n">z</span> <span class="o">+</span> <span class="n">sep</span> <span class="o">*</span> <span class="n">cos</span><span class="p">(</span><span class="n">phi</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">charge</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">p</span><span class="o">.</span><span class="n">charge</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">molecule</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">p</span><span class="o">.</span><span class="n">molecule</span> <span class="o">=</span> <span class="n">p0</span><span class="o">.</span><span class="n">molecule</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">add_particle</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">add_bond</span><span class="p">(</span><span class="n">p0</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">p0</span><span class="o">.</span><span class="n">bonded_to</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">add_particle_bonding</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">p_</span> <span class="ow">in</span> <span class="n">p0</span><span class="o">.</span><span class="n">bonded_to</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">p_</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">p</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">add_angle</span><span class="p">(</span><span class="n">p_</span><span class="p">,</span> <span class="n">p0</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">p_b</span> <span class="ow">in</span> <span class="n">p_</span><span class="o">.</span><span class="n">bonded_to</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">p_b</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">p0</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">add_dihedral</span><span class="p">(</span><span class="n">p_b</span><span class="p">,</span> <span class="n">p_</span><span class="p">,</span> <span class="n">p0</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">p</span></div>

<div class="viewcode-block" id="System.add_particle"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.add_particle">[docs]</a>    <span class="k">def</span> <span class="nf">add_particle</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">p</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.add_particle</span>

<span class="sd">        Add new :class:`~pysimm.system.Particle` to :class:`~pysimm.system.System`.</span>

<span class="sd">        Args:</span>
<span class="sd">            p: new :class:`~pysimm.system.Particle` object to be added</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">p</span><span class="p">)</span></div>

<div class="viewcode-block" id="System.rotate"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.rotate">[docs]</a>    <span class="k">def</span> <span class="nf">rotate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">around</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">theta_x</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">theta_y</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">theta_z</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">rot_matrix</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.rotate</span>

<span class="sd">        *** REQUIRES NUMPY ***</span>

<span class="sd">        Rotates entire system around given :class:`~pysimm.system.Particle` by user defined angles</span>

<span class="sd">        Args:</span>
<span class="sd">            around: :class:`~pysimm.system.Particle` around which :class:`~pysimm.system.System` will be rotated default=None</span>
<span class="sd">            theta_x: angle around which system will be rotated on x axis</span>
<span class="sd">            theta_y: angle around which system will be rotated on y axis</span>
<span class="sd">            theta_z: angle around which system will be rotated on z axis</span>
<span class="sd">            rot_matrix: rotation matrix to use for rotation</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">np</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">PysimmError</span><span class="p">(</span><span class="s1">&#39;pysimm.system.System.rotate function requires numpy&#39;</span><span class="p">)</span>
        <span class="n">theta_x</span> <span class="o">=</span> <span class="n">random</span><span class="p">()</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">pi</span> <span class="k">if</span> <span class="n">theta_x</span> <span class="ow">is</span> <span class="s1">&#39;random&#39;</span> <span class="k">else</span> <span class="n">theta_x</span>
        <span class="n">theta_y</span> <span class="o">=</span> <span class="n">random</span><span class="p">()</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">pi</span> <span class="k">if</span> <span class="n">theta_y</span> <span class="ow">is</span> <span class="s1">&#39;random&#39;</span> <span class="k">else</span> <span class="n">theta_y</span>
        <span class="n">theta_z</span> <span class="o">=</span> <span class="n">random</span><span class="p">()</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">pi</span> <span class="k">if</span> <span class="n">theta_z</span> <span class="ow">is</span> <span class="s1">&#39;random&#39;</span> <span class="k">else</span> <span class="n">theta_z</span>
        <span class="k">if</span> <span class="n">around</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">around</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">set_cog</span><span class="p">()</span>
            <span class="n">around</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cog</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
            <span class="n">around</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cog</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
            <span class="n">around</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cog</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">around</span><span class="p">,</span> <span class="n">Particle</span><span class="p">):</span>
            <span class="n">around</span> <span class="o">=</span> <span class="p">[</span><span class="n">around</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">around</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">around</span><span class="o">.</span><span class="n">z</span><span class="p">]</span>
        <span class="k">if</span> <span class="p">(</span><span class="nb">isinstance</span><span class="p">(</span><span class="n">around</span><span class="p">,</span> <span class="nb">list</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">around</span><span class="p">)</span> <span class="o">==</span> <span class="mi">3</span> <span class="ow">and</span>
                <span class="nb">len</span><span class="p">(</span><span class="nb">set</span><span class="p">([</span><span class="nb">isinstance</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="nb">float</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">around</span><span class="p">]))</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">around</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="nb">float</span><span class="p">)):</span>
            <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
                <span class="n">p</span><span class="o">.</span><span class="n">x</span> <span class="o">-=</span> <span class="n">around</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                <span class="n">p</span><span class="o">.</span><span class="n">y</span> <span class="o">-=</span> <span class="n">around</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
                <span class="n">p</span><span class="o">.</span><span class="n">z</span> <span class="o">-=</span> <span class="n">around</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
                <span class="k">if</span> <span class="n">rot_matrix</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">z</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="p">(</span><span class="n">rot_matrix</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">matrix</span><span class="p">([[</span><span class="n">p</span><span class="o">.</span><span class="n">x</span><span class="p">],</span> <span class="p">[</span><span class="n">p</span><span class="o">.</span><span class="n">y</span><span class="p">],</span> <span class="p">[</span><span class="n">p</span><span class="o">.</span><span class="n">z</span><span class="p">]]))</span><span class="o">.</span><span class="n">tolist</span><span class="p">()]</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">z</span> <span class="o">=</span> <span class="n">rotate_vector</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">z</span><span class="p">,</span> <span class="n">theta_x</span><span class="p">,</span> <span class="n">theta_y</span><span class="p">,</span> <span class="n">theta_z</span><span class="p">)</span>
                <span class="n">p</span><span class="o">.</span><span class="n">x</span> <span class="o">+=</span> <span class="n">around</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                <span class="n">p</span><span class="o">.</span><span class="n">y</span> <span class="o">+=</span> <span class="n">around</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
                <span class="n">p</span><span class="o">.</span><span class="n">z</span> <span class="o">+=</span> <span class="n">around</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span></div>

<div class="viewcode-block" id="System.make_new_bonds"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.make_new_bonds">[docs]</a>    <span class="k">def</span> <span class="nf">make_new_bonds</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">p1</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">p2</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">f</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">angles</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">dihedrals</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">impropers</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.make_new_bonds</span>

<span class="sd">        Makes new bond between two particles and updates new force field types</span>

<span class="sd">        Args:</span>
<span class="sd">            p1: :class:`~pysimm.system.Particle` object involved in new bond</span>
<span class="sd">            p2: :class:`~pysimm.system.Particle` object involved in new bond</span>
<span class="sd">            f: :class:`~pysimm.forcefield.Forcefield` object from which new force field types will be retrieved</span>
<span class="sd">            angles: True to update new angles default=True</span>
<span class="sd">            dihedrals: True to update new dihedrals default=True</span>
<span class="sd">            impropers: True to update new impropers default=True</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">add_particle_bonding</span><span class="p">()</span>
        
        <span class="k">if</span> <span class="n">p1</span><span class="o">.</span><span class="n">molecule</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">p2</span><span class="o">.</span><span class="n">molecule</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">p1</span><span class="o">.</span><span class="n">molecule</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">count</span> <span class="o">&lt;</span> <span class="n">p2</span><span class="o">.</span><span class="n">molecule</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">count</span><span class="p">:</span>
                <span class="n">old_molecule_tag</span> <span class="o">=</span> <span class="n">p1</span><span class="o">.</span><span class="n">molecule</span><span class="o">.</span><span class="n">tag</span>
                <span class="k">for</span> <span class="n">p_</span> <span class="ow">in</span> <span class="n">p1</span><span class="o">.</span><span class="n">molecule</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
                    <span class="n">p_</span><span class="o">.</span><span class="n">molecule</span> <span class="o">=</span> <span class="n">p2</span><span class="o">.</span><span class="n">molecule</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">old_molecule_tag</span> <span class="o">=</span> <span class="n">p2</span><span class="o">.</span><span class="n">molecule</span><span class="o">.</span><span class="n">tag</span>
                <span class="k">for</span> <span class="n">p_</span> <span class="ow">in</span> <span class="n">p2</span><span class="o">.</span><span class="n">molecule</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
                    <span class="n">p_</span><span class="o">.</span><span class="n">molecule</span> <span class="o">=</span> <span class="n">p1</span><span class="o">.</span><span class="n">molecule</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">molecules</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">old_molecule_tag</span><span class="p">)</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">add_bond</span><span class="p">(</span><span class="n">p1</span><span class="p">,</span> <span class="n">p2</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">angles</span> <span class="ow">or</span> <span class="n">dihedrals</span> <span class="ow">or</span> <span class="n">impropers</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">p1</span><span class="o">.</span><span class="n">bonded_to</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">angles</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">p</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">p2</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">add_angle</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">p1</span><span class="p">,</span> <span class="n">p2</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">dihedrals</span><span class="p">:</span>
                    <span class="k">for</span> <span class="n">pb</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bonded_to</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">pb</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">p1</span> <span class="ow">and</span> <span class="n">p</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">p2</span><span class="p">:</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">add_dihedral</span><span class="p">(</span><span class="n">pb</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">p1</span><span class="p">,</span> <span class="n">p2</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">p2</span><span class="o">.</span><span class="n">bonded_to</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">angles</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">p</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">p1</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">add_angle</span><span class="p">(</span><span class="n">p1</span><span class="p">,</span> <span class="n">p2</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">dihedrals</span><span class="p">:</span>
                    <span class="k">for</span> <span class="n">pb</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bonded_to</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">pb</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">p2</span> <span class="ow">and</span> <span class="n">p</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">p1</span><span class="p">:</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">add_dihedral</span><span class="p">(</span><span class="n">p1</span><span class="p">,</span> <span class="n">p2</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">pb</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">dihedrals</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">pb1</span> <span class="ow">in</span> <span class="n">p1</span><span class="o">.</span><span class="n">bonded_to</span><span class="p">:</span>
                    <span class="k">for</span> <span class="n">pb2</span> <span class="ow">in</span> <span class="n">p2</span><span class="o">.</span><span class="n">bonded_to</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">pb1</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">p2</span> <span class="ow">and</span> <span class="n">pb2</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">p1</span><span class="p">:</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">add_dihedral</span><span class="p">(</span><span class="n">pb1</span><span class="p">,</span> <span class="n">p1</span><span class="p">,</span> <span class="n">p2</span><span class="p">,</span> <span class="n">pb2</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">impropers</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">ff_class</span> <span class="o">==</span> <span class="s1">&#39;2&#39;</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">perm</span> <span class="ow">in</span> <span class="n">permutations</span><span class="p">(</span><span class="n">p1</span><span class="o">.</span><span class="n">bonded_to</span><span class="p">,</span> <span class="mi">3</span><span class="p">):</span>
                    <span class="n">unique</span> <span class="o">=</span> <span class="bp">True</span>
                    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">impropers</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">i</span><span class="o">.</span><span class="n">a</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">p1</span><span class="p">:</span>
                            <span class="k">continue</span>
                        <span class="k">if</span> <span class="nb">set</span><span class="p">([</span><span class="n">i</span><span class="o">.</span><span class="n">b</span><span class="p">,</span> <span class="n">i</span><span class="o">.</span><span class="n">c</span><span class="p">,</span> <span class="n">i</span><span class="o">.</span><span class="n">d</span><span class="p">])</span> <span class="o">==</span> <span class="nb">set</span><span class="p">([</span><span class="n">perm</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">perm</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
                                                        <span class="n">perm</span><span class="p">[</span><span class="mi">2</span><span class="p">]]):</span>
                            <span class="n">unique</span> <span class="o">=</span> <span class="bp">False</span>
                            <span class="k">break</span>
                    <span class="k">if</span> <span class="n">unique</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">add_improper</span><span class="p">(</span><span class="n">p1</span><span class="p">,</span> <span class="n">perm</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">perm</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">perm</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">f</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">perm</span> <span class="ow">in</span> <span class="n">permutations</span><span class="p">(</span><span class="n">p2</span><span class="o">.</span><span class="n">bonded_to</span><span class="p">,</span> <span class="mi">3</span><span class="p">):</span>
                    <span class="n">unique</span> <span class="o">=</span> <span class="bp">True</span>
                    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">impropers</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">i</span><span class="o">.</span><span class="n">a</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">p2</span><span class="p">:</span>
                            <span class="k">continue</span>
                        <span class="k">if</span> <span class="nb">set</span><span class="p">([</span><span class="n">i</span><span class="o">.</span><span class="n">b</span><span class="p">,</span> <span class="n">i</span><span class="o">.</span><span class="n">c</span><span class="p">,</span> <span class="n">i</span><span class="o">.</span><span class="n">d</span><span class="p">])</span> <span class="o">==</span> <span class="nb">set</span><span class="p">([</span><span class="n">perm</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">perm</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
                                                        <span class="n">perm</span><span class="p">[</span><span class="mi">2</span><span class="p">]]):</span>
                            <span class="n">unique</span> <span class="o">=</span> <span class="bp">False</span>
                            <span class="k">break</span>
                    <span class="k">if</span> <span class="n">unique</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">add_improper</span><span class="p">(</span><span class="n">p2</span><span class="p">,</span> <span class="n">perm</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">perm</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">perm</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">f</span><span class="p">)</span></div>

<div class="viewcode-block" id="System.add_bond"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.add_bond">[docs]</a>    <span class="k">def</span> <span class="nf">add_bond</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">a</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">f</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.add_bond</span>

<span class="sd">        Add :class:`~pysimm.system.Bond` to system between two particles</span>

<span class="sd">        Args:</span>
<span class="sd">            a: :class:`~pysimm.system.Particle` involved in new :class:`~pysimm.system.Bond`</span>
<span class="sd">            b: :class:`~pysimm.system.Particle` involved in new :class:`~pysimm.system.Bond`</span>
<span class="sd">            f: :class:`~pysimm.forcefield.Forcefield` object from which new force field type will be retrieved</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">a</span> <span class="ow">is</span> <span class="n">b</span><span class="p">:</span>
            <span class="k">return</span>
        <span class="n">a_name</span> <span class="o">=</span> <span class="n">a</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">eq_bond</span> <span class="ow">or</span> <span class="n">a</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span>
        <span class="n">b_name</span> <span class="o">=</span> <span class="n">b</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">eq_bond</span> <span class="ow">or</span> <span class="n">b</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span>
        <span class="n">btype</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bond_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">a_name</span><span class="p">,</span> <span class="n">b_name</span><span class="p">))</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">btype</span> <span class="ow">and</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">btype</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">bond_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">a_name</span><span class="p">,</span> <span class="n">b_name</span><span class="p">))</span>
            <span class="k">if</span> <span class="n">btype</span><span class="p">:</span>
                <span class="n">bt</span> <span class="o">=</span> <span class="n">btype</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">bond_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">bt</span><span class="p">)</span>
            <span class="n">btype</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bond_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">a_name</span><span class="p">,</span> <span class="n">b_name</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">btype</span><span class="p">:</span>
            <span class="n">new_b</span> <span class="o">=</span> <span class="n">Bond</span><span class="p">(</span><span class="nb">type</span><span class="o">=</span><span class="n">btype</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">a</span><span class="o">=</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="n">b</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">new_b</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">a</span><span class="o">.</span><span class="n">bonded_to</span> <span class="ow">is</span> <span class="bp">None</span> <span class="ow">or</span> <span class="n">b</span><span class="o">.</span><span class="n">bonded_to</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">add_particle_bonding</span><span class="p">()</span>
            <span class="k">if</span> <span class="n">a</span><span class="o">.</span><span class="n">bonded_to</span> <span class="ow">and</span> <span class="n">b</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">a</span><span class="o">.</span><span class="n">bonded_to</span><span class="p">:</span>
                <span class="n">a</span><span class="o">.</span><span class="n">bonded_to</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">b</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">b</span><span class="o">.</span><span class="n">bonded_to</span> <span class="ow">and</span> <span class="n">a</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">b</span><span class="o">.</span><span class="n">bonded_to</span><span class="p">:</span>
                <span class="n">b</span><span class="o">.</span><span class="n">bonded_to</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">error_print</span><span class="p">(</span><span class="s1">&#39;error: system does not contain bond type named </span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1"> &#39;</span>
                        <span class="s1">&#39;or could not find type in forcefield supplied&#39;</span>
                        <span class="o">%</span> <span class="p">(</span><span class="n">a_name</span><span class="p">,</span> <span class="n">b_name</span><span class="p">))</span>
            <span class="k">return</span></div>

<div class="viewcode-block" id="System.add_angle"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.add_angle">[docs]</a>    <span class="k">def</span> <span class="nf">add_angle</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">a</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">f</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.add_angle</span>

<span class="sd">        Add :class:`~pysimm.system.Angle` to system between three particles</span>

<span class="sd">        Args:</span>
<span class="sd">            a: :class:`~pysimm.system.Particle` involved in new :class:`~pysimm.system.Angle`</span>
<span class="sd">            b: :class:`~pysimm.system.Particle` involved in new :class:`~pysimm.system.Angle` (middle particle)</span>
<span class="sd">            c: :class:`~pysimm.system.Particle` involved in new :class:`~pysimm.system.Angle`</span>
<span class="sd">            f: :class:`~pysimm.forcefield.Forcefield` object from which new force field type will be retrieved</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">a</span> <span class="ow">is</span> <span class="n">c</span><span class="p">:</span>
            <span class="k">return</span>
        <span class="n">a_name</span> <span class="o">=</span> <span class="n">a</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">eq_angle</span> <span class="ow">or</span> <span class="n">a</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span>
        <span class="n">b_name</span> <span class="o">=</span> <span class="n">b</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">eq_angle</span> <span class="ow">or</span> <span class="n">b</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span>
        <span class="n">c_name</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">eq_angle</span> <span class="ow">or</span> <span class="n">c</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span>
        <span class="n">atype</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span>
            <span class="s1">&#39;</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">a_name</span><span class="p">,</span> <span class="n">b_name</span><span class="p">,</span> <span class="n">c_name</span><span class="p">),</span>
            <span class="n">item_wildcard</span><span class="o">=</span><span class="bp">None</span>
        <span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">atype</span> <span class="ow">and</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">atype</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span>
                <span class="s1">&#39;</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">a_name</span><span class="p">,</span> <span class="n">b_name</span><span class="p">,</span> <span class="n">c_name</span><span class="p">)</span>
            <span class="p">)</span>
            <span class="n">atype</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span>
                <span class="n">f</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span>
                    <span class="s1">&#39;</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">a_name</span><span class="p">,</span> <span class="n">b_name</span><span class="p">,</span> <span class="n">c_name</span><span class="p">)</span>
                <span class="p">)</span>
            <span class="p">)</span>
            
            <span class="n">atype</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">atype</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">count</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">))</span>
            
            <span class="k">if</span> <span class="n">atype</span><span class="p">:</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">atype</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">item_wildcard</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
                    <span class="n">atype</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">atype</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">copy</span><span class="p">())</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">atype</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">atype</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">item_wildcard</span><span class="o">=</span><span class="bp">None</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
        <span class="k">elif</span> <span class="n">atype</span><span class="p">:</span>
            <span class="n">atype</span> <span class="o">=</span> <span class="n">atype</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">atype</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">angles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">Angle</span><span class="p">(</span><span class="nb">type</span><span class="o">=</span><span class="n">atype</span><span class="p">,</span> <span class="n">a</span><span class="o">=</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="n">c</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">error_print</span><span class="p">(</span><span class="s1">&#39;error: system does not contain angle type named &#39;</span>
                        <span class="s1">&#39;</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1"> or could not find type in forcefield supplied&#39;</span>
                        <span class="o">%</span> <span class="p">(</span><span class="n">a_name</span><span class="p">,</span> <span class="n">b_name</span><span class="p">,</span> <span class="n">c_name</span><span class="p">))</span>
            <span class="k">return</span></div>

<div class="viewcode-block" id="System.add_dihedral"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.add_dihedral">[docs]</a>    <span class="k">def</span> <span class="nf">add_dihedral</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">a</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">d</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">f</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.add_dihedral</span>

<span class="sd">        Add :class:`~pysimm.system.Dihedral` to system between four particles</span>

<span class="sd">        Args:</span>
<span class="sd">            a: :class:`~pysimm.system.Particle` involved in new :class:`~pysimm.system.Dihedral`</span>
<span class="sd">            b: :class:`~pysimm.system.Particle` involved in new :class:`~pysimm.system.Dihedral` (middle particle)</span>
<span class="sd">            c: :class:`~pysimm.system.Particle` involved in new :class:`~pysimm.system.Dihedral` (middle particle)</span>
<span class="sd">            d: :class:`~pysimm.system.Particle` involved in new :class:`~pysimm.system.Dihedral`</span>
<span class="sd">            f: :class:`~pysimm.forcefield.Forcefield` object from which new force field type will be retrieved</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">a</span> <span class="ow">is</span> <span class="n">c</span> <span class="ow">or</span> <span class="n">b</span> <span class="ow">is</span> <span class="n">d</span><span class="p">:</span>
            <span class="k">return</span>
        <span class="n">a_name</span> <span class="o">=</span> <span class="n">a</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">eq_dihedral</span> <span class="ow">or</span> <span class="n">a</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span>
        <span class="n">b_name</span> <span class="o">=</span> <span class="n">b</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">eq_dihedral</span> <span class="ow">or</span> <span class="n">b</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span>
        <span class="n">c_name</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">eq_dihedral</span> <span class="ow">or</span> <span class="n">c</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span>
        <span class="n">d_name</span> <span class="o">=</span> <span class="n">d</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">eq_dihedral</span> <span class="ow">or</span> <span class="n">d</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span>
        <span class="n">dtype</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span>
            <span class="s1">&#39;</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">a_name</span><span class="p">,</span> <span class="n">b_name</span><span class="p">,</span> <span class="n">c_name</span><span class="p">,</span> <span class="n">d_name</span><span class="p">),</span>
            <span class="n">item_wildcard</span><span class="o">=</span><span class="bp">None</span>
        <span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">dtype</span> <span class="ow">and</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">dtype</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span>
                <span class="s1">&#39;</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">a_name</span><span class="p">,</span> <span class="n">b_name</span><span class="p">,</span> <span class="n">c_name</span><span class="p">,</span> <span class="n">d_name</span><span class="p">)</span>
            <span class="p">)</span>
            <span class="n">dtype</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span>
                <span class="n">f</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span>
                    <span class="s1">&#39;</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">a_name</span><span class="p">,</span> <span class="n">b_name</span><span class="p">,</span> <span class="n">c_name</span><span class="p">,</span> <span class="n">d_name</span><span class="p">)</span>
                <span class="p">)</span>
            <span class="p">)</span>
            
            <span class="n">dtype</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">dtype</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">count</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">))</span>
            
            <span class="k">if</span> <span class="n">dtype</span><span class="p">:</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">dtype</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">item_wildcard</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
                    <span class="n">dtype</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">dtype</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">copy</span><span class="p">())</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">dtype</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">dtype</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">item_wildcard</span><span class="o">=</span><span class="bp">None</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
            
        <span class="k">elif</span> <span class="n">dtype</span><span class="p">:</span>
            <span class="n">dtype</span> <span class="o">=</span> <span class="n">dtype</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">dtype</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">dihedrals</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">Dihedral</span><span class="p">(</span><span class="nb">type</span><span class="o">=</span><span class="n">dtype</span><span class="p">,</span> <span class="n">a</span><span class="o">=</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="o">=</span><span class="n">d</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">error_print</span><span class="p">(</span><span class="s1">&#39;error: system does not contain dihedral type named &#39;</span>
                        <span class="s1">&#39;</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1"> or could not find type in forcefield &#39;</span>
                        <span class="s1">&#39;supplied&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">a_name</span><span class="p">,</span> <span class="n">b_name</span><span class="p">,</span>
                                      <span class="n">c_name</span><span class="p">,</span> <span class="n">d_name</span><span class="p">))</span>
            <span class="n">error_print</span><span class="p">(</span><span class="s1">&#39;tags: </span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">d</span><span class="o">.</span><span class="n">tag</span><span class="p">))</span>
            <span class="k">return</span></div>

<div class="viewcode-block" id="System.add_improper"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.add_improper">[docs]</a>    <span class="k">def</span> <span class="nf">add_improper</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">a</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">d</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">f</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.add_improper</span>

<span class="sd">        Add :class:`~pysimm.system.Improper` to system between four particles</span>

<span class="sd">        Args:</span>
<span class="sd">            a: :class:`~pysimm.system.pysimm.system.Particle` involved in new :class:`~pysimm.system.Improper` (middle particle)</span>
<span class="sd">            b: :class:`~pysimm.system.pysimm.system.Particle` involved in new :class:`~pysimm.system.Improper`</span>
<span class="sd">            c: :class:`~pysimm.system.pysimm.system.Particle` involved in new :class:`~pysimm.system.Improper`</span>
<span class="sd">            d: :class:`~pysimm.system.pysimm.system.Particle` involved in new :class:`~pysimm.system.Improper`</span>
<span class="sd">            f: :class:`~pysimm.system.pysimm.forcefield.Forcefield` object from which new force field type will be retrieved</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">a</span> <span class="ow">is</span> <span class="n">b</span> <span class="ow">or</span> <span class="n">a</span> <span class="ow">is</span> <span class="n">c</span> <span class="ow">or</span> <span class="n">a</span> <span class="ow">is</span> <span class="n">d</span><span class="p">:</span>
            <span class="k">return</span>
        <span class="n">a_name</span> <span class="o">=</span> <span class="n">a</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">eq_improper</span> <span class="ow">or</span> <span class="n">a</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span>
        <span class="n">b_name</span> <span class="o">=</span> <span class="n">b</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">eq_improper</span> <span class="ow">or</span> <span class="n">b</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span>
        <span class="n">c_name</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">eq_improper</span> <span class="ow">or</span> <span class="n">c</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span>
        <span class="n">d_name</span> <span class="o">=</span> <span class="n">d</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">eq_improper</span> <span class="ow">or</span> <span class="n">d</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span>
        <span class="n">itype</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">&#39;</span>
                                        <span class="o">%</span> <span class="p">(</span><span class="n">a_name</span><span class="p">,</span> <span class="n">b_name</span><span class="p">,</span>
                                           <span class="n">c_name</span><span class="p">,</span> <span class="n">d_name</span><span class="p">),</span>
                                        <span class="n">improper_type</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span>
                                        <span class="n">item_wildcard</span><span class="o">=</span><span class="bp">None</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">itype</span> <span class="ow">and</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">itype</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span>
                <span class="s1">&#39;</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">a_name</span><span class="p">,</span> <span class="n">b_name</span><span class="p">,</span> <span class="n">c_name</span><span class="p">,</span> <span class="n">d_name</span><span class="p">),</span>
                <span class="n">improper_type</span><span class="o">=</span><span class="bp">True</span>
            <span class="p">)</span>
            <span class="n">itype</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span>
                <span class="n">f</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span>
                    <span class="s1">&#39;</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">a_name</span><span class="p">,</span> <span class="n">b_name</span><span class="p">,</span> <span class="n">c_name</span><span class="p">,</span> <span class="n">d_name</span><span class="p">),</span>
                    <span class="n">improper_type</span><span class="o">=</span><span class="bp">True</span>
                <span class="p">)</span>
            <span class="p">)</span>
                
            <span class="n">itype</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">itype</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">count</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">))</span>
            
            <span class="k">if</span> <span class="n">itype</span><span class="p">:</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">itype</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">item_wildcard</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">improper_type</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
                    <span class="n">itype</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">itype</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">copy</span><span class="p">())</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">itype</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">itype</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">item_wildcard</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">improper_type</span><span class="o">=</span><span class="bp">True</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
            
        <span class="k">elif</span> <span class="n">itype</span><span class="p">:</span>
            <span class="n">itype</span> <span class="o">=</span> <span class="n">itype</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                
        <span class="k">if</span> <span class="n">itype</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">impropers</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">Improper</span><span class="p">(</span><span class="nb">type</span><span class="o">=</span><span class="n">itype</span><span class="p">,</span> <span class="n">a</span><span class="o">=</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="o">=</span><span class="n">d</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span></div>

<div class="viewcode-block" id="System.check_forcefield"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.check_forcefield">[docs]</a>    <span class="k">def</span> <span class="nf">check_forcefield</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.check_forcefield</span>

<span class="sd">        Iterates through particles and prints the following:</span>
<span class="sd">        </span>
<span class="sd">        tag</span>
<span class="sd">        type name</span>
<span class="sd">        type element</span>
<span class="sd">        type description</span>
<span class="sd">        bonded elements</span>

<span class="sd">        Args:</span>
<span class="sd">            None</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">objectified</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">objectify</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="n">p</span><span class="o">.</span><span class="n">bond_elements</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">elem</span> <span class="k">if</span> <span class="n">p</span> <span class="ow">is</span> <span class="n">x</span><span class="o">.</span><span class="n">b</span> <span class="k">else</span>
                               <span class="n">x</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">elem</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bonds</span><span class="p">]</span>
            <span class="n">p</span><span class="o">.</span><span class="n">nbonds</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">bond_elements</span><span class="p">)</span>
            <span class="k">print</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">elem</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">desc</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">bond_elements</span><span class="p">)</span></div>

<div class="viewcode-block" id="System.apply_forcefield"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.apply_forcefield">[docs]</a>    <span class="k">def</span> <span class="nf">apply_forcefield</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="n">charges</span><span class="o">=</span><span class="s1">&#39;default&#39;</span><span class="p">,</span> <span class="n">set_box</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">box_padding</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span>
                         <span class="n">update_ptypes</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">skip_ptypes</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.apply_forcefield</span>

<span class="sd">        Applies force field data to :class:`~pysimm.system.System` based on typing rules defined in :class:`~pysimm.forcefield.Forcefield` object f</span>

<span class="sd">        Args:</span>
<span class="sd">            f: :class:`~pysimm.forcefield.Forcefield` object from which new force field type will be retrieved</span>
<span class="sd">            charges: type of charges to be applied default=&#39;default&#39;</span>
<span class="sd">            set_box: Update simulation box information based on particle positions default=True</span>
<span class="sd">            box_padding: Add padding to simulation box if updating dimensions default=10 (Angstroms)</span>
<span class="sd">            update_ptypes: If True, update particle types based on current :class:`~pysimm.system.ParticleType` names default=False</span>
<span class="sd">            skip_ptypes: if True, do not change particle types</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">ff_class</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">ff_class</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">forcefield</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">name</span>
        <span class="k">if</span> <span class="n">update_ptypes</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">update_particle_types_from_forcefield</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
            <span class="n">skip_ptypes</span> <span class="o">=</span> <span class="bp">True</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">skip_ptypes</span><span class="p">:</span>
            <span class="n">f</span><span class="o">.</span><span class="n">assign_ptypes</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">f</span><span class="o">.</span><span class="n">assign_btypes</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="n">f</span><span class="o">.</span><span class="n">assign_atypes</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="n">f</span><span class="o">.</span><span class="n">assign_dtypes</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="n">f</span><span class="o">.</span><span class="n">assign_itypes</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">charges</span><span class="p">:</span>
            <span class="n">f</span><span class="o">.</span><span class="n">assign_charges</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">charges</span><span class="o">=</span><span class="n">charges</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">set_box</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">set_box</span><span class="p">(</span><span class="n">box_padding</span><span class="p">,</span> <span class="n">center</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span></div>

<div class="viewcode-block" id="System.apply_charges"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.apply_charges">[docs]</a>    <span class="k">def</span> <span class="nf">apply_charges</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="n">charges</span><span class="o">=</span><span class="s1">&#39;default&#39;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.apply_charges</span>

<span class="sd">        Applies charges derived using method provided by user. Defaults to &#39;default&#39;. Calls :func:`~pysimm.forcefield.Forcefield.assign_charges` method of forcefield object provided.</span>

<span class="sd">        Args:</span>
<span class="sd">            f: :class:`~pysimm.forcefield.Forcefield` object</span>
<span class="sd">            charges: type of charges to be applied default=&#39;default&#39;</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">f</span><span class="o">.</span><span class="n">assign_charges</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">charges</span><span class="o">=</span><span class="n">charges</span><span class="p">)</span></div>
        
<div class="viewcode-block" id="System.write_lammps_mol"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.write_lammps_mol">[docs]</a>    <span class="k">def</span> <span class="nf">write_lammps_mol</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">out_data</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.write_lammps_mol</span>

<span class="sd">        Write :class:`~pysimm.system.System` data formatted as LAMMPS molecule template</span>

<span class="sd">        Args:</span>
<span class="sd">            out_data: where to write data, file name or &#39;string&#39;</span>

<span class="sd">        Returns:</span>
<span class="sd">            None or string if data file if out_data=&#39;string&#39;</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">out_data</span> <span class="o">==</span> <span class="s1">&#39;string&#39;</span><span class="p">:</span>
            <span class="n">out_file</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">out_file</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">out_data</span><span class="p">,</span> <span class="s1">&#39;w+&#39;</span><span class="p">)</span>
            
        <span class="bp">self</span><span class="o">.</span><span class="n">set_mass</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_cog</span><span class="p">()</span>
            
        <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="se">\n\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
        <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> atoms</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">count</span><span class="p">)</span>
        <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> bonds</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">count</span><span class="p">)</span>
        <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> angles</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">angles</span><span class="o">.</span><span class="n">count</span><span class="p">)</span>
        <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> dihedrals</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedrals</span><span class="o">.</span><span class="n">count</span><span class="p">)</span>
        <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> impropers</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">impropers</span><span class="o">.</span><span class="n">count</span><span class="p">)</span>
        
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;Coords</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
                <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{} {} {} {}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">z</span><span class="p">))</span>
        
        <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;Types</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
                <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{} {}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">tag</span><span class="p">))</span>
        
        <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;Charges</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
                <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{} {}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">charge</span><span class="p">))</span>
        
        <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;Bonds</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="p">:</span>
                <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{} {} {} {}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">b</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">b</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">b</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">))</span>
        
        <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">angles</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;Angles</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">angles</span><span class="p">:</span>
                <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{} {} {} {} {}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">tag</span><span class="p">))</span>
        
        <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedrals</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;Dihedrals</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedrals</span><span class="p">:</span>
                <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{} {} {} {} {} {}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">d</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">d</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">d</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">d</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">d</span><span class="o">.</span><span class="n">d</span><span class="o">.</span><span class="n">tag</span><span class="p">))</span>
        
        <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">impropers</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;Impropers</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">impropers</span><span class="p">:</span>
                <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{} {} {} {} {} {}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">i</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">i</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">i</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">i</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">i</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">i</span><span class="o">.</span><span class="n">d</span><span class="o">.</span><span class="n">tag</span><span class="p">))</span>
                
        <span class="k">if</span> <span class="n">out_data</span> <span class="o">==</span> <span class="s1">&#39;string&#39;</span><span class="p">:</span>
            <span class="n">s</span> <span class="o">=</span> <span class="n">out_file</span><span class="o">.</span><span class="n">getvalue</span><span class="p">()</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
            <span class="k">return</span> <span class="n">s</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">close</span><span class="p">()</span></div>
        

<div class="viewcode-block" id="System.write_lammps"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.write_lammps">[docs]</a>    <span class="k">def</span> <span class="nf">write_lammps</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">out_data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.write_lammps</span>

<span class="sd">        Write :class:`~pysimm.system.System` data formatted for LAMMPS</span>

<span class="sd">        Args:</span>
<span class="sd">            out_data: where to write data, file name or &#39;string&#39;</span>

<span class="sd">        Returns:</span>
<span class="sd">            None or string if data file if out_data=&#39;string&#39;</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">empty</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;empty&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">out_data</span> <span class="o">==</span> <span class="s1">&#39;string&#39;</span><span class="p">:</span>
            <span class="n">out_file</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">out_file</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">out_data</span><span class="p">,</span> <span class="s1">&#39;w+&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">empty</span><span class="p">:</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="se">\n\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> atoms</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="mi">0</span><span class="p">)</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> bonds</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="mi">0</span><span class="p">)</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> angles</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="mi">0</span><span class="p">)</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> dihedrals</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="mi">0</span><span class="p">)</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> impropers</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="mi">0</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="se">\n\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> atoms</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">count</span><span class="p">)</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> bonds</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">count</span><span class="p">)</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> angles</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">angles</span><span class="o">.</span><span class="n">count</span><span class="p">)</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> dihedrals</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedrals</span><span class="o">.</span><span class="n">count</span><span class="p">)</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> impropers</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">impropers</span><span class="o">.</span><span class="n">count</span><span class="p">)</span>

        <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>

        <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> atom types</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">count</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">bond_types</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> bond types</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">bond_types</span><span class="o">.</span><span class="n">count</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> angle types</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">count</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> dihedral types</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">count</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> improper types</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">count</span><span class="p">)</span>

        <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>

        <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%f</span><span class="s1"> </span><span class="si">%f</span><span class="s1"> xlo xhi</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xlo</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xhi</span><span class="p">))</span>
        <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%f</span><span class="s1"> </span><span class="si">%f</span><span class="s1"> ylo yhi</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">ylo</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">yhi</span><span class="p">))</span>
        <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%f</span><span class="s1"> </span><span class="si">%f</span><span class="s1"> zlo zhi</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zlo</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zhi</span><span class="p">))</span>

        <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;Masses</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">pt</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">pt</span><span class="o">.</span><span class="n">mass</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                    <span class="n">error_print</span><span class="p">(</span><span class="s1">&#39;error: some particle types do not have masses&#39;</span><span class="p">)</span>
                    <span class="k">return</span>
                <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%4d</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="s1"># </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">pt</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">pt</span><span class="o">.</span><span class="n">mass</span><span class="p">,</span> <span class="n">pt</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">write_coeffs</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;Pair Coeffs</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">pt</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="p">:</span>
                <span class="k">if</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">pair_style</span> <span class="ow">and</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">pair_style</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;lj&#39;</span><span class="p">)</span> <span class="ow">or</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">pair_style</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;class2&#39;</span><span class="p">))</span> <span class="ow">and</span>
                        <span class="n">pt</span><span class="o">.</span><span class="n">sigma</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">pt</span><span class="o">.</span><span class="n">epsilon</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">):</span>
                    <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%4d</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="s1"># </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span>
                                   <span class="o">%</span> <span class="p">(</span><span class="n">pt</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">pt</span><span class="o">.</span><span class="n">epsilon</span><span class="p">,</span> <span class="n">pt</span><span class="o">.</span><span class="n">sigma</span><span class="p">,</span> <span class="n">pt</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
                <span class="k">elif</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">pair_style</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">pair_style</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;buck&#39;</span><span class="p">)</span> <span class="ow">and</span>
                        <span class="n">pt</span><span class="o">.</span><span class="n">a</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">pt</span><span class="o">.</span><span class="n">rho</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">pt</span><span class="o">.</span><span class="n">c</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">):</span>
                    <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%4d</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="s1"># </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span>
                                   <span class="o">%</span> <span class="p">(</span><span class="n">pt</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">pt</span><span class="o">.</span><span class="n">a</span><span class="p">,</span> <span class="n">pt</span><span class="o">.</span><span class="n">rho</span><span class="p">,</span> <span class="n">pt</span><span class="o">.</span><span class="n">c</span><span class="p">,</span> <span class="n">pt</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
                <span class="k">elif</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">pair_style</span> <span class="ow">and</span> <span class="n">pt</span><span class="o">.</span><span class="n">sigma</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">pt</span><span class="o">.</span><span class="n">epsilon</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                    <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%4d</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="s1"># </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span>
                                   <span class="o">%</span> <span class="p">(</span><span class="n">pt</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">pt</span><span class="o">.</span><span class="n">epsilon</span><span class="p">,</span> <span class="n">pt</span><span class="o">.</span><span class="n">sigma</span><span class="p">,</span> <span class="n">pt</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
                <span class="k">elif</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">pair_style</span> <span class="ow">and</span> <span class="n">pt</span><span class="o">.</span><span class="n">a</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">pt</span><span class="o">.</span><span class="n">rho</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">pt</span><span class="o">.</span><span class="n">c</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                    <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%4d</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="s1"># </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span>
                                   <span class="o">%</span> <span class="p">(</span><span class="n">pt</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">pt</span><span class="o">.</span><span class="n">a</span><span class="p">,</span> <span class="n">pt</span><span class="o">.</span><span class="n">rho</span><span class="p">,</span> <span class="n">pt</span><span class="o">.</span><span class="n">c</span><span class="p">,</span> <span class="n">pt</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">error_print</span><span class="p">(</span><span class="s1">&#39;error: cannot understand your pair style&#39;</span><span class="p">)</span>
                    <span class="k">return</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">write_coeffs</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">bond_types</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;Bond Coeffs</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bond_types</span><span class="p">:</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">bond_style</span> <span class="o">==</span> <span class="s1">&#39;harmonic&#39;</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">ff_class</span> <span class="o">==</span> <span class="s1">&#39;1&#39;</span><span class="p">:</span>
                    <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%4d</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="s1"># </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span>
                                   <span class="o">%</span> <span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">b</span><span class="o">.</span><span class="n">k</span><span class="p">,</span> <span class="n">b</span><span class="o">.</span><span class="n">r0</span><span class="p">,</span> <span class="n">b</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
                <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">bond_style</span> <span class="o">==</span> <span class="s1">&#39;class2&#39;</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">ff_class</span> <span class="o">==</span> <span class="s1">&#39;2&#39;</span><span class="p">:</span>
                    <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%4d</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="s1"># </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span>
                                   <span class="o">%</span> <span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">b</span><span class="o">.</span><span class="n">r0</span><span class="p">,</span> <span class="n">b</span><span class="o">.</span><span class="n">k2</span><span class="p">,</span> <span class="n">b</span><span class="o">.</span><span class="n">k3</span><span class="p">,</span> <span class="n">b</span><span class="o">.</span><span class="n">k4</span><span class="p">,</span> <span class="n">b</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">error_print</span><span class="p">(</span><span class="s1">&#39;error: cannot understand your bond style&#39;</span><span class="p">)</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">write_coeffs</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;Angle Coeffs</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="p">:</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">angle_style</span> <span class="o">==</span> <span class="s1">&#39;harmonic&#39;</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">ff_class</span> <span class="o">==</span> <span class="s1">&#39;1&#39;</span><span class="p">:</span>
                    <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%4d</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="s1">&#39;</span>
                                   <span class="s1">&#39;</span><span class="si">%s</span><span class="se">\t</span><span class="s1"># </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span>
                                   <span class="o">%</span> <span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">k</span><span class="p">,</span>
                                      <span class="n">a</span><span class="o">.</span><span class="n">theta0</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
                <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">angle_style</span> <span class="o">==</span> <span class="s1">&#39;class2&#39;</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">ff_class</span> <span class="o">==</span> <span class="s1">&#39;2&#39;</span><span class="p">:</span>
                    <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%4d</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="s1">&#39;</span>
                                   <span class="s1">&#39;</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="s1"># </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span>
                                   <span class="o">%</span> <span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">theta0</span><span class="p">,</span>
                                      <span class="n">a</span><span class="o">.</span><span class="n">k2</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">k3</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">k4</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">write_coeffs</span> <span class="ow">and</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ff_class</span> <span class="o">==</span> <span class="s1">&#39;2&#39;</span> <span class="ow">or</span>
                                            <span class="bp">self</span><span class="o">.</span><span class="n">angle_style</span> <span class="o">==</span> <span class="s1">&#39;class2&#39;</span><span class="p">)):</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;BondBond Coeffs</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="p">:</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">a</span><span class="o">.</span><span class="n">m</span><span class="p">:</span>
                    <span class="n">a</span><span class="o">.</span><span class="n">m</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">a</span><span class="o">.</span><span class="n">r1</span><span class="p">:</span>
                        <span class="n">a</span><span class="o">.</span><span class="n">r1</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">a</span><span class="o">.</span><span class="n">r2</span><span class="p">:</span>
                        <span class="n">a</span><span class="o">.</span><span class="n">r2</span> <span class="o">=</span> <span class="mf">0.0</span>
                <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%4d</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="s1"># </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span>
                               <span class="o">%</span> <span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">m</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">r1</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">r2</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;BondAngle Coeffs</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="p">:</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">a</span><span class="o">.</span><span class="n">n1</span><span class="p">:</span>
                    <span class="n">a</span><span class="o">.</span><span class="n">n1</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">a</span><span class="o">.</span><span class="n">r1</span><span class="p">:</span>
                        <span class="n">a</span><span class="o">.</span><span class="n">r1</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">a</span><span class="o">.</span><span class="n">r2</span><span class="p">:</span>
                        <span class="n">a</span><span class="o">.</span><span class="n">r2</span> <span class="o">=</span> <span class="mf">0.0</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">a</span><span class="o">.</span><span class="n">n2</span><span class="p">:</span>
                    <span class="n">a</span><span class="o">.</span><span class="n">n2</span> <span class="o">=</span> <span class="mf">0.0</span>
                <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%4d</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="s1"># </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span>
                               <span class="o">%</span> <span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">n1</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">n2</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">r1</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">r2</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">write_coeffs</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;Dihedral Coeffs</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">dt</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">:</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_style</span> <span class="o">==</span> <span class="s1">&#39;fourier&#39;</span><span class="p">:</span>
                    <span class="n">dt_str</span> <span class="o">=</span> <span class="s1">&#39;{:4d}</span><span class="se">\t</span><span class="s1">{}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">dt</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">dt</span><span class="o">.</span><span class="n">m</span><span class="p">)</span>
                    <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">d</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">dt</span><span class="o">.</span><span class="n">k</span><span class="p">,</span> <span class="n">dt</span><span class="o">.</span><span class="n">n</span><span class="p">,</span> <span class="n">dt</span><span class="o">.</span><span class="n">d</span><span class="p">):</span>
                        <span class="n">dt_str</span> <span class="o">+=</span> <span class="s1">&#39;</span><span class="se">\t</span><span class="s1">{}</span><span class="se">\t</span><span class="s1">{}</span><span class="se">\t</span><span class="s1">{}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">d</span><span class="p">)</span>
                    <span class="n">dt_str</span> <span class="o">+=</span> <span class="s1">&#39;</span><span class="se">\t</span><span class="s1"># {}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">dt</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
                    <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">dt_str</span><span class="p">)</span>
                <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_style</span> <span class="o">==</span> <span class="s1">&#39;harmonic&#39;</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">ff_class</span> <span class="o">==</span> <span class="s1">&#39;1&#39;</span><span class="p">:</span>
                    <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%4d</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%2s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="s1"># </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span>
                                   <span class="o">%</span> <span class="p">(</span><span class="n">dt</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">dt</span><span class="o">.</span><span class="n">k</span><span class="p">,</span> <span class="n">dt</span><span class="o">.</span><span class="n">d</span><span class="p">,</span> <span class="n">dt</span><span class="o">.</span><span class="n">n</span><span class="p">,</span> <span class="n">dt</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
                <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_style</span> <span class="o">==</span> <span class="s1">&#39;class2&#39;</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">ff_class</span> <span class="o">==</span> <span class="s1">&#39;2&#39;</span><span class="p">:</span>
                    <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%4d</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="s1"># </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span>
                                   <span class="o">%</span> <span class="p">(</span><span class="n">dt</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">dt</span><span class="o">.</span><span class="n">k1</span><span class="p">,</span> <span class="n">dt</span><span class="o">.</span><span class="n">phi1</span><span class="p">,</span> <span class="n">dt</span><span class="o">.</span><span class="n">k2</span><span class="p">,</span> <span class="n">dt</span><span class="o">.</span><span class="n">phi2</span><span class="p">,</span> <span class="n">dt</span><span class="o">.</span><span class="n">k3</span><span class="p">,</span>
                                      <span class="n">dt</span><span class="o">.</span><span class="n">phi3</span><span class="p">,</span> <span class="n">dt</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">write_coeffs</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ff_class</span> <span class="o">==</span> <span class="s1">&#39;2&#39;</span> <span class="ow">or</span>
                                        <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_style</span> <span class="o">==</span> <span class="s1">&#39;class2&#39;</span><span class="p">):</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;MiddleBondTorsion Coeffs</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">:</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">a1</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">a1</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">r2</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">r2</span> <span class="o">=</span> <span class="mf">0.0</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">a2</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">a2</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">r2</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">r2</span> <span class="o">=</span> <span class="mf">0.0</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">a3</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">a3</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">r2</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">r2</span> <span class="o">=</span> <span class="mf">0.0</span>
                <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%4d</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="s1"># </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span>
                               <span class="o">%</span> <span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">d</span><span class="o">.</span><span class="n">a1</span><span class="p">,</span> <span class="n">d</span><span class="o">.</span><span class="n">a2</span><span class="p">,</span> <span class="n">d</span><span class="o">.</span><span class="n">a3</span><span class="p">,</span> <span class="n">d</span><span class="o">.</span><span class="n">r2</span><span class="p">,</span> <span class="n">d</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;EndBondTorsion Coeffs</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">:</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">b1</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">b1</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">r1</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">r1</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">r3</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">r3</span> <span class="o">=</span> <span class="mf">0.0</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">b2</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">b2</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">r1</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">r1</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">r3</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">r3</span> <span class="o">=</span> <span class="mf">0.0</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">b3</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">b3</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">r1</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">r1</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">r3</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">r3</span> <span class="o">=</span> <span class="mf">0.0</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">c1</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">c1</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">r1</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">r1</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">r3</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">r3</span> <span class="o">=</span> <span class="mf">0.0</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">c2</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">c2</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">r1</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">r1</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">r3</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">r3</span> <span class="o">=</span> <span class="mf">0.0</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">c3</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">c3</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">r1</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">r1</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">r3</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">r3</span> <span class="o">=</span> <span class="mf">0.0</span>
                <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%4d</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="s1"># </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span>
                               <span class="o">%</span> <span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span>
                                  <span class="n">d</span><span class="o">.</span><span class="n">b1</span><span class="p">,</span> <span class="n">d</span><span class="o">.</span><span class="n">b2</span><span class="p">,</span> <span class="n">d</span><span class="o">.</span><span class="n">b3</span><span class="p">,</span>
                                  <span class="n">d</span><span class="o">.</span><span class="n">c1</span><span class="p">,</span> <span class="n">d</span><span class="o">.</span><span class="n">c2</span><span class="p">,</span> <span class="n">d</span><span class="o">.</span><span class="n">c3</span><span class="p">,</span>
                                  <span class="n">d</span><span class="o">.</span><span class="n">r1</span><span class="p">,</span> <span class="n">d</span><span class="o">.</span><span class="n">r3</span><span class="p">,</span>
                                  <span class="n">d</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;AngleTorsion Coeffs</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">:</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">d1</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">d1</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">theta1</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">theta1</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">theta2</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">theta2</span> <span class="o">=</span> <span class="mf">0.0</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">d2</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">d2</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">theta1</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">theta1</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">theta2</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">theta2</span> <span class="o">=</span> <span class="mf">0.0</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">d3</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">d3</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">theta1</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">theta1</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">theta2</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">theta2</span> <span class="o">=</span> <span class="mf">0.0</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">e1</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">e1</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">theta1</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">theta1</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">theta2</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">theta2</span> <span class="o">=</span> <span class="mf">0.0</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">e2</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">e2</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">theta1</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">theta1</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">theta2</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">theta2</span> <span class="o">=</span> <span class="mf">0.0</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">e3</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">e3</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">theta1</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">theta1</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">theta2</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">theta2</span> <span class="o">=</span> <span class="mf">0.0</span>
                <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%4d</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="s1"># </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span>
                               <span class="o">%</span> <span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span>
                                  <span class="n">d</span><span class="o">.</span><span class="n">d1</span><span class="p">,</span> <span class="n">d</span><span class="o">.</span><span class="n">d2</span><span class="p">,</span> <span class="n">d</span><span class="o">.</span><span class="n">d3</span><span class="p">,</span>
                                  <span class="n">d</span><span class="o">.</span><span class="n">e1</span><span class="p">,</span> <span class="n">d</span><span class="o">.</span><span class="n">e2</span><span class="p">,</span> <span class="n">d</span><span class="o">.</span><span class="n">e3</span><span class="p">,</span>
                                  <span class="n">d</span><span class="o">.</span><span class="n">theta1</span><span class="p">,</span> <span class="n">d</span><span class="o">.</span><span class="n">theta2</span><span class="p">,</span>
                                  <span class="n">d</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;AngleAngleTorsion Coeffs</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">:</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">m</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">m</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">theta1</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">theta1</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">theta2</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">theta2</span> <span class="o">=</span> <span class="mf">0.0</span>
                <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%4d</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="s1"># </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span>
                               <span class="o">%</span> <span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span>
                                  <span class="n">d</span><span class="o">.</span><span class="n">m</span><span class="p">,</span>
                                  <span class="n">d</span><span class="o">.</span><span class="n">theta1</span><span class="p">,</span> <span class="n">d</span><span class="o">.</span><span class="n">theta2</span><span class="p">,</span>
                                  <span class="n">d</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;BondBond13 Coeffs</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">:</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">n_class2</span><span class="p">:</span>
                    <span class="n">d</span><span class="o">.</span><span class="n">n_class2</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">r1</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">r1</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">r3</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">r3</span> <span class="o">=</span> <span class="mf">0.0</span>
                <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%4d</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="s1"># </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span>
                               <span class="o">%</span> <span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span>
                                  <span class="n">d</span><span class="o">.</span><span class="n">n_class2</span><span class="p">,</span>
                                  <span class="n">d</span><span class="o">.</span><span class="n">r1</span><span class="p">,</span> <span class="n">d</span><span class="o">.</span><span class="n">r3</span><span class="p">,</span>
                                  <span class="n">d</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">write_coeffs</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;Improper Coeffs</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="p">:</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">improper_style</span> <span class="o">==</span> <span class="s1">&#39;harmonic&#39;</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">improper_style</span> <span class="o">==</span><span class="s1">&#39;class2&#39;</span><span class="p">:</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">i</span><span class="o">.</span><span class="n">k</span><span class="p">:</span>
                        <span class="n">i</span><span class="o">.</span><span class="n">k</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">i</span><span class="o">.</span><span class="n">x0</span><span class="p">:</span>
                        <span class="n">i</span><span class="o">.</span><span class="n">x0</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%4d</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="s1"># </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span>
                                   <span class="o">%</span> <span class="p">(</span><span class="n">i</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">i</span><span class="o">.</span><span class="n">k</span><span class="p">,</span> <span class="n">i</span><span class="o">.</span><span class="n">x0</span><span class="p">,</span> <span class="n">i</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
                <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">improper_style</span> <span class="o">==</span> <span class="s1">&#39;cvff&#39;</span><span class="p">:</span>
                    <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%4d</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="s1"># </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span>
                                   <span class="o">%</span> <span class="p">(</span><span class="n">i</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">i</span><span class="o">.</span><span class="n">k</span><span class="p">,</span> <span class="n">i</span><span class="o">.</span><span class="n">d</span><span class="p">,</span> <span class="n">i</span><span class="o">.</span><span class="n">n</span><span class="p">,</span> <span class="n">i</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">write_coeffs</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ff_class</span> <span class="o">==</span> <span class="s1">&#39;2&#39;</span> <span class="ow">or</span>
                                              <span class="bp">self</span><span class="o">.</span><span class="n">improper_style</span> <span class="o">==</span> <span class="s1">&#39;class2&#39;</span><span class="p">):</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;AngleAngle Coeffs</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="p">:</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">i</span><span class="o">.</span><span class="n">m1</span><span class="p">:</span>
                    <span class="n">i</span><span class="o">.</span><span class="n">m1</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">i</span><span class="o">.</span><span class="n">theta1</span><span class="p">:</span>
                        <span class="n">i</span><span class="o">.</span><span class="n">theta1</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">i</span><span class="o">.</span><span class="n">theta2</span><span class="p">:</span>
                        <span class="n">i</span><span class="o">.</span><span class="n">theta2</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">i</span><span class="o">.</span><span class="n">theta3</span><span class="p">:</span>
                        <span class="n">i</span><span class="o">.</span><span class="n">theta3</span> <span class="o">=</span> <span class="mf">0.0</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">i</span><span class="o">.</span><span class="n">m2</span><span class="p">:</span>
                    <span class="n">i</span><span class="o">.</span><span class="n">m2</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">i</span><span class="o">.</span><span class="n">theta1</span><span class="p">:</span>
                        <span class="n">i</span><span class="o">.</span><span class="n">theta1</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">i</span><span class="o">.</span><span class="n">theta2</span><span class="p">:</span>
                        <span class="n">i</span><span class="o">.</span><span class="n">theta2</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">i</span><span class="o">.</span><span class="n">theta3</span><span class="p">:</span>
                        <span class="n">i</span><span class="o">.</span><span class="n">theta3</span> <span class="o">=</span> <span class="mf">0.0</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">i</span><span class="o">.</span><span class="n">m3</span><span class="p">:</span>
                    <span class="n">i</span><span class="o">.</span><span class="n">m3</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">i</span><span class="o">.</span><span class="n">theta1</span><span class="p">:</span>
                        <span class="n">i</span><span class="o">.</span><span class="n">theta1</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">i</span><span class="o">.</span><span class="n">theta2</span><span class="p">:</span>
                        <span class="n">i</span><span class="o">.</span><span class="n">theta2</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">i</span><span class="o">.</span><span class="n">theta3</span><span class="p">:</span>
                        <span class="n">i</span><span class="o">.</span><span class="n">theta3</span> <span class="o">=</span> <span class="mf">0.0</span>
                <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%4d</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="s1"># </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span>
                               <span class="o">%</span> <span class="p">(</span><span class="n">i</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span>
                                  <span class="n">i</span><span class="o">.</span><span class="n">m1</span><span class="p">,</span> <span class="n">i</span><span class="o">.</span><span class="n">m2</span><span class="p">,</span> <span class="n">i</span><span class="o">.</span><span class="n">m3</span><span class="p">,</span>
                                  <span class="n">i</span><span class="o">.</span><span class="n">theta1</span><span class="p">,</span> <span class="n">i</span><span class="o">.</span><span class="n">theta2</span><span class="p">,</span> <span class="n">i</span><span class="o">.</span><span class="n">theta3</span><span class="p">,</span>
                                  <span class="n">i</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">empty</span><span class="p">:</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;Atoms</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">p</span><span class="o">.</span><span class="n">molecule</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">molecule</span> <span class="o">=</span> <span class="n">Item</span><span class="p">()</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">molecule</span><span class="o">.</span><span class="n">tag</span> <span class="o">=</span> <span class="mi">1</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">p</span><span class="o">.</span><span class="n">charge</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">charge</span> <span class="o">=</span> <span class="mi">0</span>
                <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">molecule</span><span class="p">,</span> <span class="nb">int</span><span class="p">):</span>
                    <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%4d</span><span class="se">\t</span><span class="si">%d</span><span class="se">\t</span><span class="si">%d</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span>
                                   <span class="o">%</span> <span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">molecule</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">charge</span><span class="p">,</span>
                                      <span class="n">p</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">z</span><span class="p">))</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%4d</span><span class="se">\t</span><span class="si">%d</span><span class="se">\t</span><span class="si">%d</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span>
                                   <span class="o">%</span> <span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">molecule</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">charge</span><span class="p">,</span>
                                      <span class="n">p</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">z</span><span class="p">))</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>

            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;Velocities</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">p</span><span class="o">.</span><span class="n">vx</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">vx</span> <span class="o">=</span> <span class="mf">0.</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">p</span><span class="o">.</span><span class="n">vy</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">vy</span> <span class="o">=</span> <span class="mf">0.</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">p</span><span class="o">.</span><span class="n">vz</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">vz</span> <span class="o">=</span> <span class="mf">0.</span>
                <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%4d</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">vx</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">vy</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">vz</span><span class="p">))</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">empty</span><span class="p">:</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;Bonds</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="p">:</span>
                <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%4d</span><span class="se">\t</span><span class="si">%d</span><span class="se">\t</span><span class="si">%d</span><span class="se">\t</span><span class="si">%d</span><span class="se">\n</span><span class="s1">&#39;</span>
                               <span class="o">%</span> <span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">b</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">b</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">b</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">))</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">angles</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">empty</span><span class="p">:</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;Angles</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">angles</span><span class="p">:</span>
                <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%4d</span><span class="se">\t</span><span class="si">%d</span><span class="se">\t</span><span class="si">%d</span><span class="se">\t</span><span class="si">%d</span><span class="se">\t</span><span class="si">%d</span><span class="se">\n</span><span class="s1">&#39;</span>
                               <span class="o">%</span> <span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">tag</span><span class="p">))</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedrals</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">empty</span><span class="p">:</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;Dihedrals</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedrals</span><span class="p">:</span>
                <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%4d</span><span class="se">\t</span><span class="si">%d</span><span class="se">\t</span><span class="si">%d</span><span class="se">\t</span><span class="si">%d</span><span class="se">\t</span><span class="si">%d</span><span class="se">\t</span><span class="si">%d</span><span class="se">\n</span><span class="s1">&#39;</span>
                               <span class="o">%</span> <span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">d</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span>
                                  <span class="n">d</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">d</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">d</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">d</span><span class="o">.</span><span class="n">d</span><span class="o">.</span><span class="n">tag</span><span class="p">))</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">impropers</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">empty</span><span class="p">:</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;Impropers</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">impropers</span><span class="p">:</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">ff_class</span> <span class="o">==</span> <span class="s1">&#39;2&#39;</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">improper_style</span> <span class="o">==</span> <span class="s1">&#39;class2&#39;</span><span class="p">:</span>
                    <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%4d</span><span class="se">\t</span><span class="si">%d</span><span class="se">\t</span><span class="si">%d</span><span class="se">\t</span><span class="si">%d</span><span class="se">\t</span><span class="si">%d</span><span class="se">\t</span><span class="si">%d</span><span class="se">\n</span><span class="s1">&#39;</span>
                                   <span class="o">%</span> <span class="p">(</span><span class="n">i</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">i</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span>
                                      <span class="n">i</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">i</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">i</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">i</span><span class="o">.</span><span class="n">d</span><span class="o">.</span><span class="n">tag</span><span class="p">))</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%4d</span><span class="se">\t</span><span class="si">%d</span><span class="se">\t</span><span class="si">%d</span><span class="se">\t</span><span class="si">%d</span><span class="se">\t</span><span class="si">%d</span><span class="se">\t</span><span class="si">%d</span><span class="se">\n</span><span class="s1">&#39;</span>
                                   <span class="o">%</span> <span class="p">(</span><span class="n">i</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">i</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span>
                                      <span class="n">i</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">i</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">i</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">i</span><span class="o">.</span><span class="n">d</span><span class="o">.</span><span class="n">tag</span><span class="p">))</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">out_data</span> <span class="o">==</span> <span class="s1">&#39;string&#39;</span><span class="p">:</span>
            <span class="n">s</span> <span class="o">=</span> <span class="n">out_file</span><span class="o">.</span><span class="n">getvalue</span><span class="p">()</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
            <span class="k">return</span> <span class="n">s</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">out_file</span><span class="o">.</span><span class="n">close</span><span class="p">()</span></div>
            
<div class="viewcode-block" id="System.write_xyz"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.write_xyz">[docs]</a>    <span class="k">def</span> <span class="nf">write_xyz</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">outfile</span><span class="o">=</span><span class="s1">&#39;data.xyz&#39;</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.write_xyz</span>

<span class="sd">        Write :class:`~pysimm.system.System` data in xyz format</span>

<span class="sd">        Args:</span>
<span class="sd">            outfile: where to write data, file name or &#39;string&#39;</span>

<span class="sd">        Returns:</span>
<span class="sd">            None or string of data file if out_data=&#39;string&#39;</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">elem</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;elem&#39;</span><span class="p">,</span> <span class="bp">True</span><span class="p">)</span>
        <span class="n">append</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;append&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">outfile</span> <span class="o">==</span> <span class="s1">&#39;string&#39;</span><span class="p">:</span>
            <span class="n">out</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">append</span><span class="p">:</span>
                <span class="n">out</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">outfile</span><span class="p">,</span> <span class="s1">&#39;a&#39;</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">out</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">outfile</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span>

        <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">count</span><span class="p">)</span>
        <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;xyz file written from pySIMM system module</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">elem</span> <span class="ow">and</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span> <span class="ow">and</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">elem</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">elem</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">z</span><span class="p">))</span>
            <span class="k">elif</span> <span class="n">elem</span> <span class="ow">and</span> <span class="n">p</span><span class="o">.</span><span class="n">elem</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">elem</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">z</span><span class="p">))</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">z</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">outfile</span> <span class="o">==</span> <span class="s1">&#39;string&#39;</span><span class="p">:</span>
            <span class="n">s</span> <span class="o">=</span> <span class="n">out</span><span class="o">.</span><span class="n">getvalue</span><span class="p">()</span>
            <span class="n">out</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
            <span class="k">return</span> <span class="n">s</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">out</span><span class="o">.</span><span class="n">close</span><span class="p">()</span></div>

<div class="viewcode-block" id="System.write_chemdoodle_json"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.write_chemdoodle_json">[docs]</a>    <span class="k">def</span> <span class="nf">write_chemdoodle_json</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">outfile</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.write_chemdoodle_json</span>

<span class="sd">        Write :class:`~pysimm.system.System` data in chemdoodle json format</span>

<span class="sd">        Args:</span>
<span class="sd">            outfile: where to write data, file name or &#39;string&#39;</span>

<span class="sd">        Returns:</span>
<span class="sd">            None or string of data file if out_data=&#39;string&#39;</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">atoms</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">bonds</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span> <span class="ow">and</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">elem</span><span class="p">:</span>
                <span class="n">atoms</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">&quot;x&quot;</span><span class="p">:</span> <span class="n">p</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="s2">&quot;y&quot;</span><span class="p">:</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="s2">&quot;z&quot;</span><span class="p">:</span> <span class="n">p</span><span class="o">.</span><span class="n">z</span><span class="p">,</span> <span class="s2">&quot;l&quot;</span><span class="p">:</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">elem</span><span class="p">,</span> <span class="s2">&quot;i&quot;</span><span class="p">:</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="s2">&quot;c&quot;</span><span class="p">:</span> <span class="n">p</span><span class="o">.</span><span class="n">charge</span><span class="p">})</span>
            <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">elem</span> <span class="ow">and</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="p">:</span>
                <span class="n">atoms</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">&quot;x&quot;</span><span class="p">:</span> <span class="n">p</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="s2">&quot;y&quot;</span><span class="p">:</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="s2">&quot;z&quot;</span><span class="p">:</span> <span class="n">p</span><span class="o">.</span><span class="n">z</span><span class="p">,</span> <span class="s2">&quot;l&quot;</span><span class="p">:</span> <span class="n">p</span><span class="o">.</span><span class="n">elem</span><span class="p">,</span> <span class="s2">&quot;i&quot;</span><span class="p">:</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="s2">&quot;c&quot;</span><span class="p">:</span> <span class="n">p</span><span class="o">.</span><span class="n">charge</span><span class="p">})</span>
            <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">elem</span><span class="p">:</span>
                <span class="n">atoms</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">&quot;x&quot;</span><span class="p">:</span> <span class="n">p</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="s2">&quot;y&quot;</span><span class="p">:</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="s2">&quot;z&quot;</span><span class="p">:</span> <span class="n">p</span><span class="o">.</span><span class="n">z</span><span class="p">,</span> <span class="s2">&quot;l&quot;</span><span class="p">:</span> <span class="n">p</span><span class="o">.</span><span class="n">elem</span><span class="p">})</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">atoms</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">&quot;x&quot;</span><span class="p">:</span> <span class="n">p</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="s2">&quot;y&quot;</span><span class="p">:</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="s2">&quot;z&quot;</span><span class="p">:</span> <span class="n">p</span><span class="o">.</span><span class="n">z</span><span class="p">,</span> <span class="s2">&quot;i&quot;</span><span class="p">:</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="s2">&quot;c&quot;</span><span class="p">:</span> <span class="n">p</span><span class="o">.</span><span class="n">charge</span><span class="p">})</span>

        <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">b</span><span class="o">.</span><span class="n">order</span><span class="p">:</span>
                <span class="n">bonds</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">&quot;b&quot;</span><span class="p">:</span> <span class="n">b</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;e&quot;</span><span class="p">:</span> <span class="n">b</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;o&quot;</span><span class="p">:</span> <span class="n">b</span><span class="o">.</span><span class="n">order</span><span class="p">})</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">bonds</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">&quot;b&quot;</span><span class="p">:</span> <span class="n">b</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;e&quot;</span><span class="p">:</span> <span class="n">b</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="o">-</span><span class="mi">1</span><span class="p">})</span>

        <span class="n">j</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;a&quot;</span><span class="p">:</span> <span class="n">atoms</span><span class="p">,</span> <span class="s2">&quot;b&quot;</span><span class="p">:</span> <span class="n">bonds</span><span class="p">}</span>

        <span class="k">if</span> <span class="n">outfile</span> <span class="o">==</span> <span class="s1">&#39;string&#39;</span><span class="p">:</span>
            <span class="n">out</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">out</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">outfile</span><span class="p">,</span> <span class="s1">&#39;w+&#39;</span><span class="p">)</span>

        <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">j</span><span class="p">))</span>

        <span class="k">if</span> <span class="n">outfile</span> <span class="o">==</span> <span class="s1">&#39;string&#39;</span><span class="p">:</span>
            <span class="n">s</span> <span class="o">=</span> <span class="n">out</span><span class="o">.</span><span class="n">getvalue</span><span class="p">()</span>
            <span class="n">out</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
            <span class="k">return</span> <span class="n">s</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">out</span><span class="o">.</span><span class="n">close</span><span class="p">()</span></div>

<div class="viewcode-block" id="System.write_mol"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.write_mol">[docs]</a>    <span class="k">def</span> <span class="nf">write_mol</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">outfile</span><span class="o">=</span><span class="s1">&#39;data.mol&#39;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.write_mol</span>

<span class="sd">        Write :class:`~pysimm.system.System` data in mol format</span>

<span class="sd">        Args:</span>
<span class="sd">            outfile: where to write data, file name or &#39;string&#39;</span>

<span class="sd">        Returns:</span>
<span class="sd">            None or string of data file if out_data=&#39;string&#39;</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">outfile</span> <span class="o">==</span> <span class="s1">&#39;string&#39;</span><span class="p">:</span>
            <span class="n">out</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">out</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">outfile</span><span class="p">,</span> <span class="s1">&#39;w+&#39;</span><span class="p">)</span>

        <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;system</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;written using pySIMM system module</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">count</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">count</span><span class="p">))</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">p</span><span class="o">.</span><span class="n">charge</span><span class="p">:</span>
                <span class="n">p</span><span class="o">.</span><span class="n">charge</span> <span class="o">=</span> <span class="mf">0.0</span>
            <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span> <span class="ow">and</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">elem</span><span class="p">:</span>
                <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%10.4f%10.4f%10.4f</span><span class="s1"> </span><span class="si">%s</span><span class="s1"> 0 </span><span class="si">%10.4f</span><span class="se">\n</span><span class="s1">&#39;</span>
                          <span class="o">%</span> <span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">z</span><span class="p">,</span> <span class="s1">&#39;{0: &gt;3}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">elem</span><span class="p">),</span>
                             <span class="n">p</span><span class="o">.</span><span class="n">charge</span><span class="p">))</span>
            <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">elem</span><span class="p">:</span>
                <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%10.4f%10.4f%10.4f</span><span class="s1"> </span><span class="si">%s</span><span class="s1"> 0 </span><span class="si">%10.4f</span><span class="se">\n</span><span class="s1">&#39;</span>
                          <span class="o">%</span> <span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">z</span><span class="p">,</span> <span class="s1">&#39;{0: &gt;3}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">elem</span><span class="p">),</span>
                             <span class="n">p</span><span class="o">.</span><span class="n">charge</span><span class="p">))</span>
            <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="p">:</span>
                <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%10.4f%10.4f%10.4f</span><span class="s1"> </span><span class="si">%s</span><span class="s1"> 0 </span><span class="si">%10.4f</span><span class="se">\n</span><span class="s1">&#39;</span>
                          <span class="o">%</span> <span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">z</span><span class="p">,</span> <span class="s1">&#39;{0: &gt;3}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">tag</span><span class="p">),</span>
                             <span class="n">p</span><span class="o">.</span><span class="n">charge</span><span class="p">))</span>

        <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">b</span><span class="o">.</span><span class="n">order</span><span class="p">:</span>
                <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span>
                          <span class="o">%</span> <span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">b</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">b</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\t</span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span>
                          <span class="o">%</span> <span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">b</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
        <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;M END&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">outfile</span> <span class="o">==</span> <span class="s1">&#39;string&#39;</span><span class="p">:</span>
            <span class="n">s</span> <span class="o">=</span> <span class="n">out</span><span class="o">.</span><span class="n">getvalue</span><span class="p">()</span>
            <span class="n">out</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
            <span class="k">return</span> <span class="n">s</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">out</span><span class="o">.</span><span class="n">close</span><span class="p">()</span></div>

<div class="viewcode-block" id="System.write_pdb"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.write_pdb">[docs]</a>    <span class="k">def</span> <span class="nf">write_pdb</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">outfile</span><span class="o">=</span><span class="s1">&#39;data.pdb&#39;</span><span class="p">,</span> <span class="n">type_names</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.write_pdb</span>

<span class="sd">        Write :class:`~pysimm.system.System` data in pdb format</span>

<span class="sd">        Args:</span>
<span class="sd">            outfile: where to write data, file name or &#39;string&#39;</span>

<span class="sd">        Returns:</span>
<span class="sd">            None or string of data file if out_data=&#39;string&#39;</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">outfile</span> <span class="o">==</span> <span class="s1">&#39;string&#39;</span><span class="p">:</span>
            <span class="n">out</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">out</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">outfile</span><span class="p">,</span> <span class="s1">&#39;w+&#39;</span><span class="p">)</span>

        <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{:&lt;10}pdb written using pySIMM system module</span><span class="se">\n</span><span class="s1">&#39;</span>
                  <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s1">&#39;HEADER&#39;</span><span class="p">))</span>
        <span class="k">for</span> <span class="n">m</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">molecules</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">particles</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">tag</span><span class="p">):</span>
                <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="p">:</span>
                    <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span>
                        <span class="s1">&#39;{:&lt;6}{:&gt;5} {:&gt;4} RES  {:4}    {: 8.3f}{: 8.3f}{: 8.3f}{:&gt;22}{:&gt;2}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                            <span class="s1">&#39;ATOM&#39;</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">4</span><span class="p">]</span> <span class="k">if</span> <span class="n">type_names</span> <span class="k">else</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">elem</span><span class="p">,</span> 
                            <span class="n">p</span><span class="o">.</span><span class="n">molecule</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">z</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">elem</span>
                        <span class="p">)</span>
                    <span class="p">)</span>
                <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">elem</span><span class="p">:</span>
                    <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span>
                        <span class="s1">&#39;{:&lt;6}{:&gt;5} {:&gt;4} RES  {:4}    {: 8.3f}{: 8.3f}{: 8.3f}{:&gt;22}{:&gt;2}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                            <span class="s1">&#39;ATOM&#39;</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">elem</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">molecule</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> 
                            <span class="n">p</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">z</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">elem</span>
                        <span class="p">)</span>
                    <span class="p">)</span>
            <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;TER</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">bonds</span><span class="p">:</span>
                <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{:&lt;6}{:&gt;5}&#39;</span>
                          <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s1">&#39;CONECT&#39;</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">tag</span><span class="p">))</span>
                <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">([</span><span class="n">x</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span> <span class="k">if</span> <span class="n">p</span> <span class="ow">is</span> <span class="n">x</span><span class="o">.</span><span class="n">b</span> <span class="k">else</span> <span class="n">x</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span>
                                 <span class="n">p</span><span class="o">.</span><span class="n">bonds</span><span class="p">]):</span>
                    <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{:&gt;5}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">t</span><span class="p">))</span>
                <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">outfile</span> <span class="o">==</span> <span class="s1">&#39;string&#39;</span><span class="p">:</span>
            <span class="n">s</span> <span class="o">=</span> <span class="n">out</span><span class="o">.</span><span class="n">getvalue</span><span class="p">()</span>
            <span class="n">out</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
            <span class="k">return</span> <span class="n">s</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">out</span><span class="o">.</span><span class="n">close</span><span class="p">()</span></div>

<div class="viewcode-block" id="System.write_yaml"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.write_yaml">[docs]</a>    <span class="k">def</span> <span class="nf">write_yaml</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">file_</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.write_yaml</span>

<span class="sd">        Write :class:`~pysimm.system.System` data in yaml format</span>

<span class="sd">        Args:</span>
<span class="sd">            outfile: file name to write data</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">n</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>

        <span class="n">s</span> <span class="o">=</span> <span class="nb">vars</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">ItemContainer</span><span class="p">):</span>
                <span class="n">s</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="nb">vars</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">k_</span><span class="p">,</span> <span class="n">v_</span> <span class="ow">in</span> <span class="n">s</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                    <span class="k">if</span> <span class="n">k_</span> <span class="o">==</span> <span class="s1">&#39;_dict&#39;</span><span class="p">:</span>
                        <span class="k">for</span> <span class="n">t</span><span class="p">,</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">v_</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                            <span class="n">s</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">k_</span><span class="p">][</span><span class="n">t</span><span class="p">]</span> <span class="o">=</span> <span class="nb">vars</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
                            <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">s</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">k_</span><span class="p">][</span><span class="n">t</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                                <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">ItemContainer</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span><span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="nb">list</span><span class="p">)</span> <span class="ow">and</span>
                                                                        <span class="n">value</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">Item</span><span class="p">)):</span>
                                    <span class="n">s</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">k_</span><span class="p">][</span><span class="n">t</span><span class="p">][</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span><span class="o">.</span><span class="n">tag</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">value</span><span class="p">]</span>
                                <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">Item</span><span class="p">)</span> <span class="ow">or</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">System</span><span class="p">)</span> <span class="ow">and</span> <span class="n">value</span><span class="o">.</span><span class="n">tag</span><span class="p">:</span>
                                    <span class="n">s</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">k_</span><span class="p">][</span><span class="n">t</span><span class="p">][</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span><span class="o">.</span><span class="n">tag</span>
            <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">Item</span><span class="p">):</span>
                <span class="n">s</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="nb">vars</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">s</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">v</span>

        <span class="k">if</span> <span class="n">file_</span> <span class="o">==</span> <span class="s1">&#39;string&#39;</span><span class="p">:</span>
            <span class="n">f</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">()</span>
            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">indent</span><span class="o">=</span><span class="mi">4</span><span class="p">,</span> <span class="n">separators</span><span class="o">=</span><span class="p">(</span><span class="s1">&#39;,&#39;</span><span class="p">,</span> <span class="s1">&#39;: &#39;</span><span class="p">)))</span>
            <span class="n">yaml_</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">getvalue</span><span class="p">()</span>
            <span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
            <span class="k">return</span> <span class="n">yaml_</span>

        <span class="k">with</span> <span class="nb">file</span><span class="p">(</span><span class="n">file_</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">indent</span><span class="o">=</span><span class="mi">4</span><span class="p">,</span> <span class="n">separators</span><span class="o">=</span><span class="p">(</span><span class="s1">&#39;,&#39;</span><span class="p">,</span> <span class="s1">&#39;: &#39;</span><span class="p">)))</span></div>

<div class="viewcode-block" id="System.consolidate_types"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.consolidate_types">[docs]</a>    <span class="k">def</span> <span class="nf">consolidate_types</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.consolidate_types</span>

<span class="sd">        Removes duplicate types and reassigns references</span>

<span class="sd">        Args:</span>
<span class="sd">            None</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">pt</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">dup</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">pt</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">dup</span> <span class="ow">and</span> <span class="n">pt</span><span class="o">.</span><span class="n">name</span> <span class="o">==</span> <span class="n">dup</span><span class="o">.</span><span class="n">name</span><span class="p">:</span>
                    <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="n">dup</span><span class="p">:</span>
                            <span class="n">p</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">pt</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">dup</span><span class="o">.</span><span class="n">tag</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">bt</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bond_types</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">dup</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bond_types</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">bt</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">dup</span> <span class="ow">and</span> <span class="n">bt</span><span class="o">.</span><span class="n">name</span> <span class="o">==</span> <span class="n">dup</span><span class="o">.</span><span class="n">name</span><span class="p">:</span>
                    <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bonds</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">b</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="n">dup</span><span class="p">:</span>
                            <span class="n">b</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">bt</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">bond_types</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">dup</span><span class="o">.</span><span class="n">tag</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">at</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">dup</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">at</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">dup</span> <span class="ow">and</span> <span class="n">at</span><span class="o">.</span><span class="n">name</span> <span class="o">==</span> <span class="n">dup</span><span class="o">.</span><span class="n">name</span><span class="p">:</span>
                    <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">angles</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">a</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="n">dup</span><span class="p">:</span>
                            <span class="n">a</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">at</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">dup</span><span class="o">.</span><span class="n">tag</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">dt</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">dup</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">dt</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">dup</span> <span class="ow">and</span> <span class="n">dt</span><span class="o">.</span><span class="n">name</span> <span class="o">==</span> <span class="n">dup</span><span class="o">.</span><span class="n">name</span><span class="p">:</span>
                    <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedrals</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">d</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="n">dup</span><span class="p">:</span>
                            <span class="n">d</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">dt</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">dup</span><span class="o">.</span><span class="n">tag</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">it</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">dup</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">it</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">dup</span> <span class="ow">and</span> <span class="n">it</span><span class="o">.</span><span class="n">name</span> <span class="o">==</span> <span class="n">dup</span><span class="o">.</span><span class="n">name</span><span class="p">:</span>
                    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">impropers</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">i</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="n">dup</span><span class="p">:</span>
                            <span class="n">i</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">it</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">dup</span><span class="o">.</span><span class="n">tag</span><span class="p">)</span></div>

<div class="viewcode-block" id="System.set_cog"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.set_cog">[docs]</a>    <span class="k">def</span> <span class="nf">set_cog</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.set_cog</span>

<span class="sd">        Calculate center of gravity of :class:`~pysimm.system.System` and assign to :class:`~pysimm.system.System`.cog</span>

<span class="sd">        Args:</span>
<span class="sd">            None</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cog</span> <span class="o">=</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">cog</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+=</span> <span class="n">p</span><span class="o">.</span><span class="n">x</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">cog</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+=</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">cog</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">+=</span> <span class="n">p</span><span class="o">.</span><span class="n">z</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">count</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">cog</span> <span class="o">=</span> <span class="p">[</span><span class="n">c</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">count</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">cog</span><span class="p">]</span></div>
        
<div class="viewcode-block" id="System.shift_particles"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.shift_particles">[docs]</a>    <span class="k">def</span> <span class="nf">shift_particles</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">shiftx</span><span class="p">,</span> <span class="n">shifty</span><span class="p">,</span> <span class="n">shiftz</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.shift_particles</span>

<span class="sd">        Shifts all particles by shiftx, shifty, shiftz. Recalculates cog.</span>

<span class="sd">        Args:</span>
<span class="sd">            shiftx: distance to shift particles in x direction</span>
<span class="sd">            shifty: distance to shift particles in y direction</span>
<span class="sd">            shiftz: distance to shift particles in z direction</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="n">p</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="n">shiftx</span><span class="p">,</span> <span class="n">shifty</span><span class="p">,</span> <span class="n">shiftz</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_cog</span><span class="p">()</span></div>
            
<div class="viewcode-block" id="System.center"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.center">[docs]</a>    <span class="k">def</span> <span class="nf">center</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">what</span><span class="o">=</span><span class="s1">&#39;particles&#39;</span><span class="p">,</span> <span class="n">at</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="n">move_both</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.center</span>

<span class="sd">        Centers particles center of geometry or simulation box at given coordinate. A vector is defined based on the current coordinate for the center of either the particles or the simulation box and the &quot;at&quot; parameter. This shift vector is applied to the entity defined by the &quot;what&quot; parameter. Optionally, both the particles and the box can be shifted by the same vector.</span>

<span class="sd">        Args:</span>
<span class="sd">            what: what is being centered: &quot;particles&quot; or &quot;box&quot;</span>
<span class="sd">            at: new coordinate for center of particles or box</span>
<span class="sd">            move_both: if True, determines vector for shift defined by &quot;what&quot; and &quot;at&quot; parameters, and applies shift to both particles and box. If false, only shift what is defined by &quot;what&quot; parameter.</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">what</span> <span class="o">==</span> <span class="s1">&#39;particles&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">set_cog</span><span class="p">()</span>
            <span class="n">move_vec</span> <span class="o">=</span> <span class="p">[</span><span class="n">at</span><span class="p">[</span><span class="n">n</span><span class="p">]</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">cog</span><span class="p">[</span><span class="n">n</span><span class="p">]</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">)]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">shift_particles</span><span class="p">(</span><span class="o">*</span><span class="n">move_vec</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">move_both</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="o">*</span><span class="n">move_vec</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">what</span> <span class="o">==</span> <span class="s1">&#39;box&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">size</span><span class="p">()</span>
            <span class="n">box_center</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xlo</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dx</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">ylo</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dy</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zlo</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dz</span><span class="o">/</span><span class="mi">2</span><span class="p">]</span>
            <span class="n">move_vec</span> <span class="o">=</span> <span class="p">[</span><span class="n">at</span><span class="p">[</span><span class="n">n</span><span class="p">]</span> <span class="o">-</span> <span class="n">box_center</span><span class="p">[</span><span class="n">n</span><span class="p">]</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">)]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="o">*</span><span class="n">move_vec</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">move_both</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">shift_particles</span><span class="p">(</span><span class="o">*</span><span class="n">move_vec</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">error_print</span><span class="p">(</span><span class="s1">&#39;can only choose to center &quot;particles&quot; or &quot;box&quot;&#39;</span><span class="p">)</span></div>

<div class="viewcode-block" id="System.center_system"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.center_system">[docs]</a>    <span class="k">def</span> <span class="nf">center_system</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.center_system</span>

<span class="sd">        DEPRECATED: Use :class:`~pysimm.system.System`.center(&#39;box&#39;, [0, 0, 0], True) instead</span>

<span class="sd">        Args:</span>
<span class="sd">            None</span>
<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">warning_print</span><span class="p">(</span><span class="s2">&quot;DEPRECATED: Use System.center(&#39;box&#39;, [0, 0, 0], True) instead of System.center_system())&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">center</span><span class="p">(</span><span class="s1">&#39;box&#39;</span><span class="p">,</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="bp">True</span><span class="p">)</span></div>

<div class="viewcode-block" id="System.center_at_origin"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.center_at_origin">[docs]</a>    <span class="k">def</span> <span class="nf">center_at_origin</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.center_at_origin</span>

<span class="sd">        DEPRECATED: Use :class:`~pysimm.system.System`.center(&#39;particles&#39;, [0, 0, 0], True) instead</span>

<span class="sd">        Args:</span>
<span class="sd">            None</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">warning_print</span><span class="p">(</span><span class="s2">&quot;DEPRECATED: Use System.center(&#39;particles&#39;, [0, 0, 0], True) instead of System.center_at_origin())&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">center</span><span class="p">(</span><span class="s1">&#39;particles&#39;</span><span class="p">,</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="bp">True</span><span class="p">)</span></div>

<div class="viewcode-block" id="System.set_mass"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.set_mass">[docs]</a>    <span class="k">def</span> <span class="nf">set_mass</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.set_mass</span>

<span class="sd">        Set total mass of particles in :class:`~pysimm.system.System`</span>

<span class="sd">        Args:</span>
<span class="sd">            None</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mass</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">mass</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">mass</span> <span class="o">=</span> <span class="mi">0</span>
                <span class="n">warning_print</span><span class="p">(</span><span class="s1">&#39;Some particles do not have a mass&#39;</span><span class="p">)</span>
                <span class="k">break</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">mass</span> <span class="o">+=</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">mass</span></div>

<div class="viewcode-block" id="System.set_volume"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.set_volume">[docs]</a>    <span class="k">def</span> <span class="nf">set_volume</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.set_volume</span>

<span class="sd">        Set volume of :class:`~pysimm.system.System` based on Dimension</span>

<span class="sd">        Args:</span>
<span class="sd">            None</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">check</span><span class="p">():</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">volume</span> <span class="o">=</span> <span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xhi</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xlo</span><span class="p">)</span> <span class="o">*</span>
                           <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">yhi</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">ylo</span><span class="p">)</span> <span class="o">*</span>
                           <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zhi</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zlo</span><span class="p">))</span></div>

<div class="viewcode-block" id="System.set_density"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.set_density">[docs]</a>    <span class="k">def</span> <span class="nf">set_density</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.set_density</span>

<span class="sd">        Calculate density of :class:`~pysimm.system.System` from mass and volume</span>

<span class="sd">        Args:</span>
<span class="sd">            None</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_mass</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_volume</span><span class="p">()</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">mass</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">volume</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">density</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mass</span> <span class="o">/</span> <span class="mf">6.02e23</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">volume</span> <span class="o">*</span> <span class="mf">1e24</span></div>

<div class="viewcode-block" id="System.set_velocity"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.set_velocity">[docs]</a>    <span class="k">def</span> <span class="nf">set_velocity</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.set_velocity</span>

<span class="sd">        Calculate total velocity of particles in :class:`~pysimm.system.System`</span>

<span class="sd">        Args:</span>
<span class="sd">            None</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">vx</span> <span class="o">=</span> <span class="mf">0.0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">vy</span> <span class="o">=</span> <span class="mf">0.0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">vz</span> <span class="o">=</span> <span class="mf">0.0</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">vx</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="n">p</span><span class="o">.</span><span class="n">vx</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">vx</span> <span class="o">+=</span> <span class="n">p</span><span class="o">.</span><span class="n">vx</span>
            <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">vy</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="n">p</span><span class="o">.</span><span class="n">vy</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">vy</span> <span class="o">+=</span> <span class="n">p</span><span class="o">.</span><span class="n">vy</span>
            <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">vz</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="n">p</span><span class="o">.</span><span class="n">vz</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">vz</span> <span class="o">+=</span> <span class="n">p</span><span class="o">.</span><span class="n">vz</span></div>

<div class="viewcode-block" id="System.zero_velocity"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.zero_velocity">[docs]</a>    <span class="k">def</span> <span class="nf">zero_velocity</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.zero_velocity</span>

<span class="sd">        Enforce zero shift velocity in :class:`~pysimm.system.System`</span>

<span class="sd">        Args:</span>
<span class="sd">            None</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_velocity</span><span class="p">()</span>
        <span class="n">shift_x</span> <span class="o">=</span> <span class="n">shift_y</span> <span class="o">=</span> <span class="n">shift_z</span> <span class="o">=</span> <span class="mf">0.0</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">vx</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">shift_x</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">vx</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">count</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">vy</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">shift_y</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">vy</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">count</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">vz</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">shift_z</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">vz</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">count</span>
        <span class="k">if</span> <span class="n">shift_x</span> <span class="o">!=</span> <span class="mi">0</span> <span class="ow">or</span> <span class="n">shift_y</span> <span class="o">!=</span> <span class="mi">0</span> <span class="ow">or</span> <span class="n">shift_z</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
                <span class="n">p</span><span class="o">.</span><span class="n">vx</span> <span class="o">-=</span> <span class="n">shift_x</span>
                <span class="n">p</span><span class="o">.</span><span class="n">vy</span> <span class="o">-=</span> <span class="n">shift_y</span>
                <span class="n">p</span><span class="o">.</span><span class="n">vz</span> <span class="o">-=</span> <span class="n">shift_z</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_velocity</span><span class="p">()</span></div>

<div class="viewcode-block" id="System.set_box"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.set_box">[docs]</a>    <span class="k">def</span> <span class="nf">set_box</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">padding</span><span class="o">=</span><span class="mf">0.</span><span class="p">,</span> <span class="n">center</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.set_box</span>

<span class="sd">        Update :class:`~pysimm.system.System`.dim with user defined padding. Used to construct a simulation box if it doesn&#39;t exist, or adjust the size of the simulation box following system modifications.</span>

<span class="sd">        Args:</span>
<span class="sd">            padding: add padding to all sides of box (Angstrom)</span>
<span class="sd">            center: if True, place center of box at origin default=True</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">xmin</span> <span class="o">=</span> <span class="n">ymin</span> <span class="o">=</span> <span class="n">zmin</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">float_info</span><span class="o">.</span><span class="n">max</span>
        <span class="n">xmax</span> <span class="o">=</span> <span class="n">ymax</span> <span class="o">=</span> <span class="n">zmax</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">float_info</span><span class="o">.</span><span class="n">min</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">x</span> <span class="o">&lt;</span> <span class="n">xmin</span><span class="p">:</span>
                <span class="n">xmin</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">x</span>
            <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">x</span> <span class="o">&gt;</span> <span class="n">xmax</span><span class="p">:</span>
                <span class="n">xmax</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">x</span>
            <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span> <span class="o">&lt;</span> <span class="n">ymin</span><span class="p">:</span>
                <span class="n">ymin</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span>
            <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span> <span class="o">&gt;</span> <span class="n">ymax</span><span class="p">:</span>
                <span class="n">ymax</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span>
            <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">z</span> <span class="o">&lt;</span> <span class="n">zmin</span><span class="p">:</span>
                <span class="n">zmin</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">z</span>
            <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">z</span> <span class="o">&gt;</span> <span class="n">zmax</span><span class="p">:</span>
                <span class="n">zmax</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">z</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xlo</span> <span class="o">=</span> <span class="n">xmin</span> <span class="o">-</span> <span class="n">padding</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xhi</span> <span class="o">=</span> <span class="n">xmax</span> <span class="o">+</span> <span class="n">padding</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">ylo</span> <span class="o">=</span> <span class="n">ymin</span> <span class="o">-</span> <span class="n">padding</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">yhi</span> <span class="o">=</span> <span class="n">ymax</span> <span class="o">+</span> <span class="n">padding</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zlo</span> <span class="o">=</span> <span class="n">zmin</span> <span class="o">-</span> <span class="n">padding</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zhi</span> <span class="o">=</span> <span class="n">zmax</span> <span class="o">+</span> <span class="n">padding</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dx</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xhi</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xlo</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dy</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">yhi</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">ylo</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zhi</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zlo</span>
        
        <span class="k">if</span> <span class="n">center</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">center</span><span class="p">(</span><span class="s1">&#39;particles&#39;</span><span class="p">,</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="bp">True</span><span class="p">)</span></div>
        
<div class="viewcode-block" id="System.set_mm_dist"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.set_mm_dist">[docs]</a>    <span class="k">def</span> <span class="nf">set_mm_dist</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">molecules</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.set_mm_dist</span>

<span class="sd">        Calculate molecular mass distribution (mainly for polymer systems).</span>
<span class="sd">        Sets :class:`~pysimm.system.System`.mw, :class:`~pysimm.system.System`.mn, and :class:`~pysimm.system.System`.disperisty</span>

<span class="sd">        Args:</span>
<span class="sd">            molecules: :class:`~pysimm.utils.ItemContainer` of molecules to calculate distributions defaul=&#39;all&#39;</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">molecules</span> <span class="ow">is</span> <span class="bp">None</span> <span class="ow">or</span> <span class="n">molecules</span> <span class="o">==</span> <span class="s1">&#39;all&#39;</span><span class="p">:</span>
            <span class="n">molecules</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">molecules</span>
        <span class="k">for</span> <span class="n">m</span> <span class="ow">in</span> <span class="n">molecules</span><span class="p">:</span>
            <span class="n">m</span><span class="o">.</span><span class="n">set_mass</span><span class="p">()</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">mn</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mw</span> <span class="o">=</span> <span class="mi">0</span>

        <span class="k">for</span> <span class="n">m</span> <span class="ow">in</span> <span class="n">molecules</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">mn</span> <span class="o">+=</span> <span class="n">m</span><span class="o">.</span><span class="n">mass</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">mw</span> <span class="o">+=</span> <span class="nb">pow</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mass</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">mw</span> <span class="o">/=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mn</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mn</span> <span class="o">/=</span> <span class="n">molecules</span><span class="o">.</span><span class="n">count</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dispersity</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mw</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">mn</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">pdi</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mw</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">mn</span></div>

<div class="viewcode-block" id="System.set_frac_free_volume"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.set_frac_free_volume">[docs]</a>    <span class="k">def</span> <span class="nf">set_frac_free_volume</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">v_void</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.set_frac_free_volume</span>

<span class="sd">        Calculates fractional free volume from void volume and bulk density</span>

<span class="sd">        Args:</span>
<span class="sd">            v_void: void volume if not defined in :class:`~pysimm.system.System`.void_volume default=None</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">v_void</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">void_volume</span><span class="p">:</span>
            <span class="n">error_print</span><span class="p">(</span><span class="s1">&#39;Void volume not provided, cannot calculate fractional free volume&#39;</span><span class="p">)</span>
            <span class="k">return</span>
        <span class="k">elif</span> <span class="ow">not</span> <span class="n">v_void</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">set_density</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">frac_free_volume</span> <span class="o">=</span> <span class="n">calc</span><span class="o">.</span><span class="n">frac_free_volume</span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="bp">self</span><span class="o">.</span><span class="n">density</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">void_volume</span><span class="p">)</span>
        <span class="k">elif</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">void_volume</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">set_density</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">frac_free_volume</span> <span class="o">=</span> <span class="n">calc</span><span class="o">.</span><span class="n">frac_free_volume</span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="bp">self</span><span class="o">.</span><span class="n">density</span><span class="p">,</span> <span class="n">v_void</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">frac_free_volume</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">frac_free_volume</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">frac_free_volume</span> <span class="o">=</span> <span class="mf">0.0</span></div>

<div class="viewcode-block" id="System.visualize"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.visualize">[docs]</a>    <span class="k">def</span> <span class="nf">visualize</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">vis_exec</span><span class="o">=</span><span class="s1">&#39;vmd&#39;</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.system.System.visualize</span>

<span class="sd">        Visualize system in third party software with given executable. Software must accept pdb or xyz as first</span>
<span class="sd">        command line argument.</span>

<span class="sd">        Args:</span>
<span class="sd">            vis_exec: executable to launch visualization software default=&#39;vmd&#39;</span>
<span class="sd">            unwrap (optional): if True, unwrap :class:`~pysimm.system.System` first default=None</span>
<span class="sd">            format (optional): set format default=&#39;xyz&#39;</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">call</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">PysimmError</span><span class="p">(</span><span class="s1">&#39;pysimm.system.System.visualize function requires subprocess.call&#39;</span><span class="p">)</span>

        <span class="n">unwrap</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;unwrap&#39;</span><span class="p">)</span>
        <span class="n">format</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;format&#39;</span><span class="p">,</span> <span class="s1">&#39;xyz&#39;</span><span class="p">)</span>

        <span class="n">verbose_print</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dx</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xlo</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xhi</span><span class="p">)</span>
        <span class="n">verbose_print</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dy</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">ylo</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">yhi</span><span class="p">)</span>
        <span class="n">verbose_print</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dz</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zlo</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zhi</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">unwrap</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">unwrap</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">format</span> <span class="o">==</span> <span class="s1">&#39;xyz&#39;</span><span class="p">:</span>
            <span class="n">name_</span> <span class="o">=</span> <span class="s1">&#39;pysimm_temp.xyz&#39;</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">write_xyz</span><span class="p">(</span><span class="n">name_</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">format</span> <span class="o">==</span> <span class="s1">&#39;pdb&#39;</span><span class="p">:</span>
            <span class="n">name_</span> <span class="o">=</span> <span class="s1">&#39;pysimm_temp.pdb&#39;</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">write_pdb</span><span class="p">(</span><span class="n">name_</span><span class="p">)</span>

        <span class="n">call</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">vis_exec</span><span class="p">,</span> <span class="n">name_</span><span class="p">),</span> <span class="n">shell</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>

        <span class="n">os</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">name_</span><span class="p">)</span></div>

<div class="viewcode-block" id="System.viz"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.System.viz">[docs]</a>    <span class="k">def</span> <span class="nf">viz</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">visualize</span><span class="p">(</span><span class="n">vis_exec</span><span class="o">=</span><span class="s1">&#39;vmd&#39;</span><span class="p">,</span> <span class="n">unwrap</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">format</span><span class="o">=</span><span class="s1">&#39;xyz&#39;</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="Molecule"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.Molecule">[docs]</a><span class="k">class</span> <span class="nc">Molecule</span><span class="p">(</span><span class="n">System</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.system.Molecule</span>

<span class="sd">    Very similar to :class:`~pysimm.system.System`, but requires less information</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">System</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></div>


<div class="viewcode-block" id="read_yaml"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.read_yaml">[docs]</a><span class="k">def</span> <span class="nf">read_yaml</span><span class="p">(</span><span class="n">file_</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.system.read_yaml</span>

<span class="sd">    Interprets yaml file and creates :class:`~pysimm.system.System` object</span>

<span class="sd">    Args:</span>
<span class="sd">        file_: yaml file name</span>

<span class="sd">    Returns:</span>
<span class="sd">        :class:`~pysimm.system.System` object</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="n">file_</span><span class="p">):</span>
        <span class="n">dict_</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="nb">file</span><span class="p">(</span><span class="n">file_</span><span class="p">)</span><span class="o">.</span><span class="n">read</span><span class="p">())</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">dict_</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">file_</span><span class="p">)</span>

    <span class="n">s</span> <span class="o">=</span> <span class="n">System</span><span class="p">()</span>

    <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">dict_</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="nb">dict</span><span class="p">):</span>
            <span class="nb">setattr</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span><span class="p">)</span>

    <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dict_</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;dim&#39;</span><span class="p">),</span> <span class="nb">dict</span><span class="p">):</span>
        <span class="n">s</span><span class="o">.</span><span class="n">dim</span> <span class="o">=</span> <span class="n">Dimension</span><span class="p">(</span><span class="o">**</span><span class="n">dict_</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;dim&#39;</span><span class="p">))</span>

    <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dict_</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;particle_types&#39;</span><span class="p">),</span> <span class="nb">dict</span><span class="p">):</span>
        <span class="n">s</span><span class="o">.</span><span class="n">particle_types</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">pt</span> <span class="ow">in</span> <span class="n">dict_</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;particle_types&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;_dict&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
            <span class="n">s</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">ParticleType</span><span class="p">(</span><span class="o">**</span><span class="n">pt</span><span class="p">))</span>

    <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dict_</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;bond_types&#39;</span><span class="p">),</span> <span class="nb">dict</span><span class="p">):</span>
        <span class="n">s</span><span class="o">.</span><span class="n">bond_types</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">bt</span> <span class="ow">in</span> <span class="n">dict_</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;bond_types&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;_dict&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
            <span class="n">s</span><span class="o">.</span><span class="n">bond_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">BondType</span><span class="p">(</span><span class="o">**</span><span class="n">bt</span><span class="p">))</span>

    <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dict_</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;angle_types&#39;</span><span class="p">),</span> <span class="nb">dict</span><span class="p">):</span>
        <span class="n">s</span><span class="o">.</span><span class="n">angle_types</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">at</span> <span class="ow">in</span> <span class="n">dict_</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;angle_types&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;_dict&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
            <span class="n">s</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">AngleType</span><span class="p">(</span><span class="o">**</span><span class="n">at</span><span class="p">))</span>

    <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dict_</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;dihedral_types&#39;</span><span class="p">),</span> <span class="nb">dict</span><span class="p">):</span>
        <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">dt</span> <span class="ow">in</span> <span class="n">dict_</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;dihedral_types&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;_dict&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
            <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">DihedralType</span><span class="p">(</span><span class="o">**</span><span class="n">dt</span><span class="p">))</span>

    <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dict_</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;improper_types&#39;</span><span class="p">),</span> <span class="nb">dict</span><span class="p">):</span>
        <span class="n">s</span><span class="o">.</span><span class="n">improper_types</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">it</span> <span class="ow">in</span> <span class="n">dict_</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;improper_types&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;_dict&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
            <span class="n">s</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">ImproperType</span><span class="p">(</span><span class="o">**</span><span class="n">it</span><span class="p">))</span>

    <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dict_</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;particles&#39;</span><span class="p">),</span> <span class="nb">dict</span><span class="p">):</span>
        <span class="n">s</span><span class="o">.</span><span class="n">particles</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">dict_</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;particles&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;_dict&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
            <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">Particle</span><span class="p">(</span><span class="o">**</span><span class="n">p</span><span class="p">))</span>

    <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dict_</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;bonds&#39;</span><span class="p">),</span> <span class="nb">dict</span><span class="p">):</span>
        <span class="n">s</span><span class="o">.</span><span class="n">bonds</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="n">dict_</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;bonds&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;_dict&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
            <span class="n">s</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">Bond</span><span class="p">(</span><span class="o">**</span><span class="n">b</span><span class="p">))</span>

    <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dict_</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;angles&#39;</span><span class="p">),</span> <span class="nb">dict</span><span class="p">):</span>
        <span class="n">s</span><span class="o">.</span><span class="n">angles</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="n">dict_</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;angles&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;_dict&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
            <span class="n">s</span><span class="o">.</span><span class="n">angles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">Angle</span><span class="p">(</span><span class="o">**</span><span class="n">a</span><span class="p">))</span>

    <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dict_</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;dihedrals&#39;</span><span class="p">),</span> <span class="nb">dict</span><span class="p">):</span>
        <span class="n">s</span><span class="o">.</span><span class="n">dihedrals</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">dict_</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;dihedrals&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;_dict&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
            <span class="n">s</span><span class="o">.</span><span class="n">dihedrals</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">Dihedral</span><span class="p">(</span><span class="o">**</span><span class="n">d</span><span class="p">))</span>

    <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dict_</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;impropers&#39;</span><span class="p">),</span> <span class="nb">dict</span><span class="p">):</span>
        <span class="n">s</span><span class="o">.</span><span class="n">impropers</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">dict_</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;impropers&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;_dict&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
            <span class="n">s</span><span class="o">.</span><span class="n">impropers</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">Improper</span><span class="p">(</span><span class="o">**</span><span class="n">i</span><span class="p">))</span>

    <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dict_</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;molecules&#39;</span><span class="p">),</span> <span class="nb">dict</span><span class="p">):</span>
        <span class="n">s</span><span class="o">.</span><span class="n">molecules</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">m</span> <span class="ow">in</span> <span class="n">dict_</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;molecules&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;_dict&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
            <span class="n">mol</span> <span class="o">=</span> <span class="n">Molecule</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">m</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="nb">list</span><span class="p">)</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">v</span><span class="p">:</span>
                    <span class="nb">setattr</span><span class="p">(</span><span class="n">mol</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">ItemContainer</span><span class="p">())</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="nb">setattr</span><span class="p">(</span><span class="n">mol</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span><span class="p">)</span>

            <span class="n">particles</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">mol</span><span class="o">.</span><span class="n">particles</span><span class="p">]</span>
            <span class="n">mol</span><span class="o">.</span><span class="n">particles</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">particles</span><span class="p">:</span>
                <span class="n">mol</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">n</span><span class="p">])</span>

            <span class="n">bonds</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">mol</span><span class="o">.</span><span class="n">bonds</span><span class="p">]</span>
            <span class="n">mol</span><span class="o">.</span><span class="n">bonds</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">bonds</span><span class="p">:</span>
                <span class="n">mol</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">bonds</span><span class="p">[</span><span class="n">n</span><span class="p">])</span>

            <span class="n">angles</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">mol</span><span class="o">.</span><span class="n">angles</span><span class="p">]</span>
            <span class="n">mol</span><span class="o">.</span><span class="n">angles</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">angles</span><span class="p">:</span>
                <span class="n">mol</span><span class="o">.</span><span class="n">angles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">angles</span><span class="p">[</span><span class="n">n</span><span class="p">])</span>

            <span class="n">dihedrals</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">mol</span><span class="o">.</span><span class="n">dihedrals</span><span class="p">]</span>
            <span class="n">mol</span><span class="o">.</span><span class="n">dihedrals</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">dihedrals</span><span class="p">:</span>
                <span class="n">mol</span><span class="o">.</span><span class="n">dihedrals</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">dihedrals</span><span class="p">[</span><span class="n">n</span><span class="p">])</span>

            <span class="n">impropers</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">mol</span><span class="o">.</span><span class="n">impropers</span><span class="p">]</span>
            <span class="n">mol</span><span class="o">.</span><span class="n">impropers</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">impropers</span><span class="p">:</span>
                <span class="n">mol</span><span class="o">.</span><span class="n">impropers</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">impropers</span><span class="p">[</span><span class="n">n</span><span class="p">])</span>

            <span class="n">s</span><span class="o">.</span><span class="n">molecules</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">mol</span><span class="p">)</span>

    <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">s</span><span class="o">.</span><span class="n">particle_types</span><span class="p">[</span><span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="p">]:</span>
            <span class="n">p</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">particle_types</span><span class="p">[</span><span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="p">]</span>

        <span class="k">if</span> <span class="n">s</span><span class="o">.</span><span class="n">molecules</span><span class="p">[</span><span class="n">p</span><span class="o">.</span><span class="n">molecule</span><span class="p">]:</span>
            <span class="n">p</span><span class="o">.</span><span class="n">molecule</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">molecules</span><span class="p">[</span><span class="n">p</span><span class="o">.</span><span class="n">molecule</span><span class="p">]</span>

        <span class="n">bonds</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bonds</span><span class="p">]</span>
        <span class="n">p</span><span class="o">.</span><span class="n">bonds</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">bonds</span><span class="p">:</span>
            <span class="n">p</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">bonds</span><span class="p">[</span><span class="n">n</span><span class="p">])</span>

        <span class="n">angles</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">angles</span><span class="p">]</span>
        <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">angles</span><span class="p">:</span>
            <span class="n">p</span><span class="o">.</span><span class="n">angles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">angles</span><span class="p">[</span><span class="n">n</span><span class="p">])</span>

        <span class="n">dihedrals</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">dihedrals</span><span class="p">]</span>
        <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">dihedrals</span><span class="p">:</span>
            <span class="n">p</span><span class="o">.</span><span class="n">dihedrals</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">dihedrals</span><span class="p">[</span><span class="n">n</span><span class="p">])</span>

        <span class="n">impropers</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">impropers</span><span class="p">]</span>
        <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">impropers</span><span class="p">:</span>
            <span class="n">p</span><span class="o">.</span><span class="n">impropers</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">impropers</span><span class="p">[</span><span class="n">n</span><span class="p">])</span>

    <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">bonds</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">s</span><span class="o">.</span><span class="n">bond_types</span><span class="p">[</span><span class="n">b</span><span class="o">.</span><span class="n">type</span><span class="p">]:</span>
            <span class="n">b</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">bond_types</span><span class="p">[</span><span class="n">b</span><span class="o">.</span><span class="n">type</span><span class="p">]</span>
        <span class="n">b</span><span class="o">.</span><span class="n">a</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">b</span><span class="o">.</span><span class="n">a</span><span class="p">]</span>
        <span class="n">b</span><span class="o">.</span><span class="n">b</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">b</span><span class="o">.</span><span class="n">b</span><span class="p">]</span>

    <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">angles</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">s</span><span class="o">.</span><span class="n">angle_types</span><span class="p">[</span><span class="n">a</span><span class="o">.</span><span class="n">type</span><span class="p">]:</span>
            <span class="n">a</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">angle_types</span><span class="p">[</span><span class="n">a</span><span class="o">.</span><span class="n">type</span><span class="p">]</span>
        <span class="n">a</span><span class="o">.</span><span class="n">a</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">a</span><span class="o">.</span><span class="n">a</span><span class="p">]</span>
        <span class="n">a</span><span class="o">.</span><span class="n">b</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">a</span><span class="o">.</span><span class="n">b</span><span class="p">]</span>
        <span class="n">a</span><span class="o">.</span><span class="n">c</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">a</span><span class="o">.</span><span class="n">c</span><span class="p">]</span>

    <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">dihedrals</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">[</span><span class="n">d</span><span class="o">.</span><span class="n">type</span><span class="p">]:</span>
            <span class="n">d</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">[</span><span class="n">d</span><span class="o">.</span><span class="n">type</span><span class="p">]</span>
        <span class="n">d</span><span class="o">.</span><span class="n">a</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">d</span><span class="o">.</span><span class="n">a</span><span class="p">]</span>
        <span class="n">d</span><span class="o">.</span><span class="n">b</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">d</span><span class="o">.</span><span class="n">b</span><span class="p">]</span>
        <span class="n">d</span><span class="o">.</span><span class="n">c</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">d</span><span class="o">.</span><span class="n">c</span><span class="p">]</span>
        <span class="n">d</span><span class="o">.</span><span class="n">d</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">d</span><span class="o">.</span><span class="n">d</span><span class="p">]</span>

    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">impropers</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">s</span><span class="o">.</span><span class="n">improper_types</span><span class="p">[</span><span class="n">i</span><span class="o">.</span><span class="n">type</span><span class="p">]:</span>
            <span class="n">i</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">improper_types</span><span class="p">[</span><span class="n">i</span><span class="o">.</span><span class="n">type</span><span class="p">]</span>
        <span class="n">i</span><span class="o">.</span><span class="n">a</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="o">.</span><span class="n">a</span><span class="p">]</span>
        <span class="n">i</span><span class="o">.</span><span class="n">b</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="o">.</span><span class="n">b</span><span class="p">]</span>
        <span class="n">i</span><span class="o">.</span><span class="n">c</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="o">.</span><span class="n">c</span><span class="p">]</span>
        <span class="n">i</span><span class="o">.</span><span class="n">d</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="o">.</span><span class="n">d</span><span class="p">]</span>

    <span class="k">return</span> <span class="n">s</span></div>


<div class="viewcode-block" id="read_xyz"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.read_xyz">[docs]</a><span class="k">def</span> <span class="nf">read_xyz</span><span class="p">(</span><span class="n">file_</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.system.read_xyz</span>

<span class="sd">    Interprets xyz file and creates :class:`~pysimm.system.System` object</span>

<span class="sd">    Args:</span>
<span class="sd">        file_: xyz file name</span>
<span class="sd">        quiet(optional): if False, print status</span>

<span class="sd">    Returns:</span>
<span class="sd">        :class:`~pysimm.system.System` object</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">quiet</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;quiet&#39;</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="n">file_</span><span class="p">):</span>
        <span class="n">debug_print</span><span class="p">(</span><span class="s1">&#39;reading file&#39;</span><span class="p">)</span>
        <span class="n">f</span> <span class="o">=</span> <span class="nb">file</span><span class="p">(</span><span class="n">file_</span><span class="p">)</span>
    <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">file_</span><span class="p">,</span> <span class="nb">basestring</span><span class="p">):</span>
        <span class="n">debug_print</span><span class="p">(</span><span class="s1">&#39;reading string&#39;</span><span class="p">)</span>
        <span class="n">f</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">(</span><span class="n">file_</span><span class="p">)</span>

    <span class="n">s</span> <span class="o">=</span> <span class="n">System</span><span class="p">()</span>
    <span class="n">nparticles</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
    <span class="n">s</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span>
    <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nparticles</span><span class="p">):</span>
        <span class="n">elem</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
        <span class="n">x</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
        <span class="n">y</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
        <span class="n">z</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">z</span><span class="p">)</span>
        <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">Particle</span><span class="p">(</span><span class="n">elem</span><span class="o">=</span><span class="n">elem</span><span class="p">,</span> <span class="n">x</span><span class="o">=</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="o">=</span><span class="n">z</span><span class="p">))</span>

    <span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

    <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
        <span class="n">pt</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">elem</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">pt</span><span class="p">:</span>
            <span class="n">p</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">pt</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">pt</span> <span class="o">=</span> <span class="n">ParticleType</span><span class="p">(</span><span class="n">elem</span><span class="o">=</span><span class="n">p</span><span class="o">.</span><span class="n">elem</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">p</span><span class="o">.</span><span class="n">elem</span><span class="p">)</span>
            <span class="n">p</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">pt</span>
            <span class="n">s</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">pt</span><span class="p">)</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span><span class="p">:</span>
        <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;read </span><span class="si">%s</span><span class="s1"> particles&#39;</span> <span class="o">%</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">count</span><span class="p">)</span>

    <span class="n">s</span><span class="o">.</span><span class="n">set_box</span><span class="p">(</span><span class="n">padding</span><span class="o">=</span><span class="mf">0.5</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">s</span></div>
    
<div class="viewcode-block" id="read_chemdoodle_json"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.read_chemdoodle_json">[docs]</a><span class="k">def</span> <span class="nf">read_chemdoodle_json</span><span class="p">(</span><span class="n">file_</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.system.read_xyz</span>

<span class="sd">    Interprets xyz file and creates :class:`~pysimm.system.System` object</span>

<span class="sd">    Args:</span>
<span class="sd">        file_: xyz file name</span>
<span class="sd">        quiet(optional): if False, print status</span>

<span class="sd">    Returns:</span>
<span class="sd">        :class:`~pysimm.system.System` object</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">quiet</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;quiet&#39;</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="n">file_</span><span class="p">):</span>
        <span class="n">debug_print</span><span class="p">(</span><span class="s1">&#39;reading file&#39;</span><span class="p">)</span>
        <span class="n">f</span> <span class="o">=</span> <span class="nb">file</span><span class="p">(</span><span class="n">file_</span><span class="p">)</span>
    <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">file_</span><span class="p">,</span> <span class="nb">basestring</span><span class="p">):</span>
        <span class="n">debug_print</span><span class="p">(</span><span class="s1">&#39;reading string&#39;</span><span class="p">)</span>
        <span class="n">f</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">(</span><span class="n">file_</span><span class="p">)</span>
        
    <span class="n">s</span> <span class="o">=</span> <span class="n">System</span><span class="p">()</span>
    <span class="n">data</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">())</span>
    <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">):</span>
        <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">Particle</span><span class="p">(</span>
            <span class="n">x</span><span class="o">=</span><span class="n">a</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">),</span>
            <span class="n">y</span><span class="o">=</span><span class="n">a</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;y&#39;</span><span class="p">),</span>
            <span class="n">z</span><span class="o">=</span><span class="n">a</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;z&#39;</span><span class="p">),</span>
            <span class="n">charge</span><span class="o">=</span><span class="n">a</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;c&#39;</span><span class="p">),</span>
            <span class="n">elem</span><span class="o">=</span><span class="n">a</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;l&#39;</span><span class="p">),</span>
            <span class="n">type_name</span><span class="o">=</span><span class="n">a</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;i&#39;</span><span class="p">)</span>
        <span class="p">))</span>
    <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">):</span>
        <span class="n">s</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">Bond</span><span class="p">(</span>
            <span class="n">a</span><span class="o">=</span><span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">b</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">)</span><span class="o">+</span><span class="mi">1</span><span class="p">],</span>
            <span class="n">b</span><span class="o">=</span><span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">b</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;e&#39;</span><span class="p">)</span><span class="o">+</span><span class="mi">1</span><span class="p">],</span>
            <span class="n">order</span><span class="o">=</span><span class="n">b</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;o&#39;</span><span class="p">)</span>
        <span class="p">))</span>
        
    <span class="k">return</span> <span class="n">s</span></div>


<div class="viewcode-block" id="read_lammps"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.read_lammps">[docs]</a><span class="k">def</span> <span class="nf">read_lammps</span><span class="p">(</span><span class="n">data_file</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.system.read_lammps</span>

<span class="sd">    Interprets LAMMPS data file and creates :class:`~pysimm.system.System` object</span>

<span class="sd">    Args:</span>
<span class="sd">        data_file: LAMMPS data file name</span>
<span class="sd">        quiet(optional): if False, print status</span>
<span class="sd">        atom_style (optional): option to let user override (understands charge, molecular, full)</span>
<span class="sd">        pair_style (optional): option to let user override</span>
<span class="sd">        bond_style (optional): option to let user override</span>
<span class="sd">        angle_style (optional): option to let user override</span>
<span class="sd">        dihedral_style (optional): option to let user override</span>
<span class="sd">        improper_style (optional): option to let user override</span>
<span class="sd">        set_types (optional): if True, objectify default=True</span>
<span class="sd">        name (optional): provide name for system</span>

<span class="sd">    Returns:</span>
<span class="sd">        :class:`~pysimm.system.System` object</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">atom_style</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;atom_style&#39;</span><span class="p">)</span>
    <span class="n">pair_style</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;pair_style&#39;</span><span class="p">)</span>
    <span class="n">bond_style</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;bond_style&#39;</span><span class="p">)</span>
    <span class="n">angle_style</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;angle_style&#39;</span><span class="p">)</span>
    <span class="n">dihedral_style</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;dihedral_style&#39;</span><span class="p">)</span>
    <span class="n">improper_style</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;improper_style&#39;</span><span class="p">)</span>
    <span class="n">set_types</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;set_types&#39;</span><span class="p">,</span> <span class="bp">True</span><span class="p">)</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;name&#39;</span><span class="p">)</span>

    <span class="n">quiet</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;quiet&#39;</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="n">data_file</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span><span class="p">:</span>
            <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;reading lammps data file &quot;</span><span class="si">%s</span><span class="s1">&quot;&#39;</span> <span class="o">%</span> <span class="n">data_file</span><span class="p">)</span>
        <span class="n">f</span> <span class="o">=</span> <span class="nb">file</span><span class="p">(</span><span class="n">data_file</span><span class="p">)</span>
    <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">data_file</span><span class="p">,</span> <span class="nb">basestring</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span><span class="p">:</span>
            <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;reading lammps data file from string&#39;</span><span class="p">)</span>
        <span class="n">f</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">(</span><span class="n">data_file</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">raise</span> <span class="n">PysimmError</span><span class="p">(</span><span class="s1">&#39;pysimm.system.read_lammps requires either &#39;</span>
                          <span class="s1">&#39;file or string as first argument&#39;</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">name</span><span class="p">:</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span><span class="p">:</span>
            <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;creating pysimm.system.System object with name </span><span class="si">%s</span><span class="s1">&#39;</span>
                      <span class="o">%</span> <span class="n">name</span><span class="p">)</span>
        <span class="n">s</span> <span class="o">=</span> <span class="n">System</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">s</span> <span class="o">=</span> <span class="n">System</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span>

    <span class="n">nparticles</span> <span class="o">=</span> <span class="n">nparticle_types</span> <span class="o">=</span> <span class="n">nbonds</span> <span class="o">=</span> <span class="n">nbond_types</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="n">nangles</span> <span class="o">=</span> <span class="n">nangle_types</span> <span class="o">=</span> <span class="n">ndihedrals</span> <span class="o">=</span> <span class="n">ndihedral_types</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="n">nimpropers</span> <span class="o">=</span> <span class="n">nimproper_types</span> <span class="o">=</span> <span class="mi">0</span>

    <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span>
        <span class="n">line</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;atoms&#39;</span><span class="p">:</span>
            <span class="n">nparticles</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;atom&#39;</span><span class="p">:</span>
            <span class="n">nparticle_types</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;bonds&#39;</span><span class="p">:</span>
            <span class="n">nbonds</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;bond&#39;</span><span class="p">:</span>
            <span class="n">nbond_types</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;angles&#39;</span><span class="p">:</span>
            <span class="n">nangles</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;angle&#39;</span><span class="p">:</span>
            <span class="n">nangle_types</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;dihedrals&#39;</span><span class="p">:</span>
            <span class="n">ndihedrals</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;dihedral&#39;</span><span class="p">:</span>
            <span class="n">ndihedral_types</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;impropers&#39;</span><span class="p">:</span>
            <span class="n">nimpropers</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;improper&#39;</span><span class="p">:</span>
            <span class="n">nimproper_types</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">3</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;xlo&#39;</span><span class="p">:</span>
            <span class="n">s</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xlo</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
            <span class="n">s</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xhi</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
            <span class="n">s</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dx</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xhi</span> <span class="o">-</span> <span class="n">s</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xlo</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">3</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;ylo&#39;</span><span class="p">:</span>
            <span class="n">s</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">ylo</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
            <span class="n">s</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">yhi</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
            <span class="n">s</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dy</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">yhi</span> <span class="o">-</span> <span class="n">s</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">ylo</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">3</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;zlo&#39;</span><span class="p">:</span>
            <span class="n">s</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zlo</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
            <span class="n">s</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zhi</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
            <span class="n">s</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dz</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zhi</span> <span class="o">-</span> <span class="n">s</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zlo</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;Masses&#39;</span><span class="p">:</span>
            <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nparticle_types</span><span class="p">):</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;#&#39;</span><span class="p">)</span>
                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                    <span class="n">line</span><span class="p">,</span> <span class="n">name</span> <span class="o">=</span> <span class="n">line</span>
                    <span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;,&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">re</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;,|\s+&#39;</span><span class="p">,</span> <span class="n">name</span><span class="o">.</span><span class="n">strip</span><span class="p">()))</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">line</span> <span class="o">=</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                    <span class="n">name</span> <span class="o">=</span> <span class="bp">None</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="n">tag</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="k">if</span> <span class="n">s</span><span class="o">.</span><span class="n">particle_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]:</span>
                    <span class="k">if</span> <span class="n">name</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                        <span class="n">s</span><span class="o">.</span><span class="n">particle_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span>
                    <span class="n">s</span><span class="o">.</span><span class="n">particle_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">mass</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">s</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">ParticleType</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span>
                                                      <span class="n">mass</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">])))</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span><span class="p">:</span>
                <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;read masses for </span><span class="si">%s</span><span class="s1"> ParticleTypes&#39;</span>
                              <span class="o">%</span> <span class="n">s</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">count</span><span class="p">)</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;Pair&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="s1">&#39;#&#39;</span> <span class="ow">in</span> <span class="n">line</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">pair_style</span><span class="p">:</span>
                <span class="n">line</span> <span class="o">=</span> <span class="s1">&#39; &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">line</span><span class="p">)</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;#&#39;</span><span class="p">)</span>
                <span class="n">pair_style</span> <span class="o">=</span> <span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
            <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nparticle_types</span><span class="p">):</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;#&#39;</span><span class="p">)</span>
                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                    <span class="n">line</span><span class="p">,</span> <span class="n">name</span> <span class="o">=</span> <span class="n">line</span>
                    <span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;,&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">re</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;,|\s+&#39;</span><span class="p">,</span> <span class="n">name</span><span class="o">.</span><span class="n">strip</span><span class="p">()))</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">line</span> <span class="o">=</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                    <span class="n">name</span> <span class="o">=</span> <span class="bp">None</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="n">tag</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="k">if</span> <span class="n">pair_style</span> <span class="ow">and</span> <span class="p">(</span><span class="n">pair_style</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;lj&#39;</span><span class="p">)</span> <span class="ow">or</span>
                                   <span class="n">pair_style</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;class2&#39;</span><span class="p">)):</span>
                    <span class="k">if</span> <span class="n">s</span><span class="o">.</span><span class="n">particle_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]:</span>
                        <span class="n">pt</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">particle_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span>
                        <span class="k">if</span> <span class="n">name</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">pt</span><span class="o">.</span><span class="n">name</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                            <span class="n">pt</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span>
                        <span class="n">pt</span><span class="o">.</span><span class="n">epsilon</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
                        <span class="n">pt</span><span class="o">.</span><span class="n">sigma</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">pt</span> <span class="o">=</span> <span class="n">ParticleType</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span>
                                          <span class="n">epsilon</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                                          <span class="n">sigma</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">]))</span>
                        <span class="n">s</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">pt</span><span class="p">)</span>
                <span class="k">elif</span> <span class="n">pair_style</span> <span class="ow">and</span> <span class="n">pair_style</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;buck&#39;</span><span class="p">):</span>
                    <span class="k">if</span> <span class="n">s</span><span class="o">.</span><span class="n">particle_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]:</span>
                        <span class="n">pt</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">particle_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span>
                        <span class="k">if</span> <span class="n">name</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">pt</span><span class="o">.</span><span class="n">name</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                            <span class="n">pt</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span>
                        <span class="n">pt</span><span class="o">.</span><span class="n">a</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
                        <span class="n">pt</span><span class="o">.</span><span class="n">rho</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
                        <span class="n">pt</span><span class="o">.</span><span class="n">c</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">pt</span> <span class="o">=</span> <span class="n">ParticleType</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span> <span class="n">a</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                                          <span class="n">rho</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span> <span class="n">c</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">3</span><span class="p">]))</span>
                        <span class="n">s</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">pt</span><span class="p">)</span>
                <span class="k">elif</span> <span class="ow">not</span> <span class="n">pair_style</span><span class="p">:</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span> <span class="ow">and</span> <span class="n">i</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                        <span class="n">warning_print</span><span class="p">(</span><span class="s1">&#39;pair_style not explicitly provided - &#39;</span>
                                      <span class="s1">&#39;guessing based on number of parameters &#39;</span>
                                      <span class="s1">&#39;(2=lj 3=buck)&#39;</span><span class="p">)</span>
                    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
                        <span class="n">pair_style</span> <span class="o">=</span> <span class="s1">&#39;lj&#39;</span>
                        <span class="k">if</span> <span class="n">s</span><span class="o">.</span><span class="n">particle_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]:</span>
                            <span class="n">pt</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">particle_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span>
                            <span class="k">if</span> <span class="n">name</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">pt</span><span class="o">.</span><span class="n">name</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                                <span class="n">pt</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span>
                            <span class="n">pt</span><span class="o">.</span><span class="n">epsilon</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
                            <span class="n">pt</span><span class="o">.</span><span class="n">sigma</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
                        <span class="k">else</span><span class="p">:</span>
                            <span class="n">pt</span> <span class="o">=</span> <span class="n">ParticleType</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span>
                                              <span class="n">epsilon</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                                              <span class="n">sigma</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">]))</span>
                            <span class="n">s</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">pt</span><span class="p">)</span>
                    <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">==</span> <span class="mi">4</span><span class="p">:</span>
                        <span class="n">pair_style</span> <span class="o">=</span> <span class="s1">&#39;buckingham&#39;</span>
                        <span class="k">if</span> <span class="n">s</span><span class="o">.</span><span class="n">particle_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]:</span>
                            <span class="n">pt</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">particle_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span>
                            <span class="k">if</span> <span class="n">name</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">pt</span><span class="o">.</span><span class="n">name</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                                <span class="n">pt</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span>
                            <span class="n">pt</span><span class="o">.</span><span class="n">a</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
                            <span class="n">pt</span><span class="o">.</span><span class="n">rho</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
                            <span class="n">pt</span><span class="o">.</span><span class="n">c</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span>
                        <span class="k">else</span><span class="p">:</span>
                            <span class="n">pt</span> <span class="o">=</span> <span class="n">ParticleType</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span> <span class="n">a</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                                              <span class="n">rho</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span> <span class="n">c</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">3</span><span class="p">]))</span>
                            <span class="n">s</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">pt</span><span class="p">)</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span> <span class="ow">and</span> <span class="n">pair_style</span><span class="p">:</span>
                <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;read &quot;</span><span class="si">%s</span><span class="s1">&quot; nonbonded parameters &#39;</span>
                              <span class="s1">&#39;for </span><span class="si">%s</span><span class="s1"> ParticleTypes&#39;</span>
                              <span class="o">%</span> <span class="p">(</span><span class="n">pair_style</span><span class="p">,</span> <span class="n">nparticle_types</span><span class="p">))</span>
            <span class="k">elif</span> <span class="ow">not</span> <span class="n">quiet</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">pair_style</span><span class="p">:</span>
                <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;cannot determine pair_style - &#39;</span>
                              <span class="s1">&#39;skipping nonbonded parameters&#39;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;Bond&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="s1">&#39;#&#39;</span> <span class="ow">in</span> <span class="n">line</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">bond_style</span><span class="p">:</span>
                <span class="n">line</span> <span class="o">=</span> <span class="s1">&#39; &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">line</span><span class="p">)</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;#&#39;</span><span class="p">)</span>
                <span class="n">bond_style</span> <span class="o">=</span> <span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
            <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nbond_types</span><span class="p">):</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;#&#39;</span><span class="p">)</span>
                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                    <span class="n">line</span><span class="p">,</span> <span class="n">name</span> <span class="o">=</span> <span class="n">line</span>
                    <span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;,&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">re</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;,|\s+&#39;</span><span class="p">,</span> <span class="n">name</span><span class="o">.</span><span class="n">strip</span><span class="p">()))</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">line</span> <span class="o">=</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                    <span class="n">name</span> <span class="o">=</span> <span class="bp">None</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="n">tag</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="k">if</span> <span class="n">bond_style</span> <span class="ow">and</span> <span class="n">bond_style</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;harm&#39;</span><span class="p">):</span>
                    <span class="n">s</span><span class="o">.</span><span class="n">bond_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">BondType</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span>
                                              <span class="n">k</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                                              <span class="n">r0</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">])))</span>
                <span class="k">elif</span> <span class="n">bond_style</span> <span class="ow">and</span> <span class="n">bond_style</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;class2&#39;</span><span class="p">):</span>
                    <span class="n">s</span><span class="o">.</span><span class="n">bond_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">BondType</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span>
                                              <span class="n">r0</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                                              <span class="n">k2</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span>
                                              <span class="n">k3</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">3</span><span class="p">]),</span>
                                              <span class="n">k4</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">4</span><span class="p">])))</span>
                <span class="k">elif</span> <span class="ow">not</span> <span class="n">bond_style</span><span class="p">:</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span> <span class="ow">and</span> <span class="n">i</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                        <span class="n">warning_print</span><span class="p">(</span><span class="s1">&#39;bond_style currently unknown - &#39;</span>
                                      <span class="s1">&#39;guessing based on number of parameters &#39;</span>
                                      <span class="s1">&#39;(2=harmonic 4=class2)&#39;</span><span class="p">)</span>
                    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
                        <span class="n">bond_style</span> <span class="o">=</span> <span class="s1">&#39;harmonic&#39;</span>
                        <span class="n">s</span><span class="o">.</span><span class="n">bond_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">BondType</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span>
                                                  <span class="n">k</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                                                  <span class="n">r0</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">])))</span>
                    <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">==</span> <span class="mi">5</span><span class="p">:</span>
                        <span class="n">bond_style</span> <span class="o">=</span> <span class="s1">&#39;class2&#39;</span>
                        <span class="n">s</span><span class="o">.</span><span class="n">bond_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">BondType</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span>
                                                  <span class="n">r0</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                                                  <span class="n">k2</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span>
                                                  <span class="n">k3</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">3</span><span class="p">]),</span>
                                                  <span class="n">k4</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">4</span><span class="p">])))</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span> <span class="ow">and</span> <span class="n">bond_style</span><span class="p">:</span>
                <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;read &quot;</span><span class="si">%s</span><span class="s1">&quot; bond parameters &#39;</span>
                              <span class="s1">&#39;for </span><span class="si">%s</span><span class="s1"> BondTypes&#39;</span>
                              <span class="o">%</span> <span class="p">(</span><span class="n">bond_style</span><span class="p">,</span> <span class="n">nbond_types</span><span class="p">))</span>
            <span class="k">elif</span> <span class="ow">not</span> <span class="n">quiet</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">bond_style</span><span class="p">:</span>
                <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;cannot determine bond_style - &#39;</span>
                              <span class="s1">&#39;skipping bond parameters&#39;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;Angle&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="s1">&#39;#&#39;</span> <span class="ow">in</span> <span class="n">line</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">angle_style</span><span class="p">:</span>
                <span class="n">line</span> <span class="o">=</span> <span class="s1">&#39; &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">line</span><span class="p">)</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;#&#39;</span><span class="p">)</span>
                <span class="n">angle_style</span> <span class="o">=</span> <span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
            <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nangle_types</span><span class="p">):</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;#&#39;</span><span class="p">)</span>
                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                    <span class="n">line</span><span class="p">,</span> <span class="n">name</span> <span class="o">=</span> <span class="n">line</span>
                    <span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;,&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">re</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;,|\s+&#39;</span><span class="p">,</span> <span class="n">name</span><span class="o">.</span><span class="n">strip</span><span class="p">()))</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">line</span> <span class="o">=</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                    <span class="n">name</span> <span class="o">=</span> <span class="bp">None</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="n">tag</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="k">if</span> <span class="n">angle_style</span> <span class="ow">and</span> <span class="n">angle_style</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;harm&#39;</span><span class="p">):</span>
                    <span class="n">s</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">AngleType</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span>
                                                <span class="n">k</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                                                <span class="n">theta0</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">])))</span>
                <span class="k">elif</span> <span class="n">angle_style</span> <span class="ow">and</span> <span class="n">angle_style</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;class2&#39;</span><span class="p">):</span>
                    <span class="n">s</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">AngleType</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span>
                                                <span class="n">theta0</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                                                <span class="n">k2</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span>
                                                <span class="n">k3</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">3</span><span class="p">]),</span>
                                                <span class="n">k4</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">4</span><span class="p">])))</span>
                <span class="k">elif</span> <span class="ow">not</span> <span class="n">angle_style</span><span class="p">:</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span> <span class="ow">and</span> <span class="n">i</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                        <span class="n">warning_print</span><span class="p">(</span><span class="s1">&#39;angle_style currently unknown - &#39;</span>
                                      <span class="s1">&#39;guessing based on number of parameters &#39;</span>
                                      <span class="s1">&#39;(2=harmonic 4=class2)&#39;</span><span class="p">)</span>
                    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
                        <span class="n">angle_style</span> <span class="o">=</span> <span class="s1">&#39;harmonic&#39;</span>
                        <span class="n">s</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">AngleType</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span>
                                                    <span class="n">k</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                                                    <span class="n">theta0</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">])))</span>
                    <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">==</span> <span class="mi">5</span><span class="p">:</span>
                        <span class="n">angle_style</span> <span class="o">=</span> <span class="s1">&#39;class2&#39;</span>
                        <span class="n">s</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">AngleType</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span>
                                                    <span class="n">theta0</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                                                    <span class="n">k2</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span>
                                                    <span class="n">k3</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">3</span><span class="p">]),</span>
                                                    <span class="n">k4</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">4</span><span class="p">])))</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span> <span class="ow">and</span> <span class="n">angle_style</span><span class="p">:</span>
                    <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;read &quot;</span><span class="si">%s</span><span class="s1">&quot; angle parameters &#39;</span>
                                  <span class="s1">&#39;for </span><span class="si">%s</span><span class="s1"> AngleTypes&#39;</span>
                                  <span class="o">%</span> <span class="p">(</span><span class="n">angle_style</span><span class="p">,</span> <span class="n">nangle_types</span><span class="p">))</span>
            <span class="k">elif</span> <span class="ow">not</span> <span class="n">quiet</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">angle_style</span><span class="p">:</span>
                <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;cannot determine angle_style - &#39;</span>
                              <span class="s1">&#39;skipping angle parameters&#39;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;BondBond&#39;</span><span class="p">:</span>
            <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nangle_types</span><span class="p">):</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="n">tag</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">angle_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">m</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">angle_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">r1</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">angle_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">r2</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span> <span class="ow">and</span> <span class="n">angle_style</span><span class="p">:</span>
                <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;read &quot;</span><span class="si">%s</span><span class="s1">&quot; angle (bond-bond) &#39;</span>
                              <span class="s1">&#39;parameters for </span><span class="si">%s</span><span class="s1"> AngleTypes&#39;</span>
                              <span class="o">%</span> <span class="p">(</span><span class="n">angle_style</span><span class="p">,</span> <span class="n">nangle_types</span><span class="p">))</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;BondAngle&#39;</span><span class="p">:</span>
            <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nangle_types</span><span class="p">):</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="n">tag</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">angle_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">n1</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">angle_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">n2</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span> <span class="ow">and</span> <span class="n">angle_style</span><span class="p">:</span>
                <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;read &quot;</span><span class="si">%s</span><span class="s1">&quot; angle (bond-angle) &#39;</span>
                              <span class="s1">&#39;parameters for </span><span class="si">%s</span><span class="s1"> AngleTypes&#39;</span>
                              <span class="o">%</span> <span class="p">(</span><span class="n">angle_style</span><span class="p">,</span> <span class="n">nangle_types</span><span class="p">))</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;Dihedral&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="s1">&#39;#&#39;</span> <span class="ow">in</span> <span class="n">line</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">dihedral_style</span><span class="p">:</span>
                <span class="n">line</span> <span class="o">=</span> <span class="s1">&#39; &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">line</span><span class="p">)</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;#&#39;</span><span class="p">)</span>
                <span class="n">dihedral_style</span> <span class="o">=</span> <span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
            <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">ndihedral_types</span><span class="p">):</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;#&#39;</span><span class="p">)</span>
                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                    <span class="n">line</span><span class="p">,</span> <span class="n">name</span> <span class="o">=</span> <span class="n">line</span>
                    <span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;,&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">re</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;,|\s+&#39;</span><span class="p">,</span> <span class="n">name</span><span class="o">.</span><span class="n">strip</span><span class="p">()))</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">line</span> <span class="o">=</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                    <span class="n">name</span> <span class="o">=</span> <span class="bp">None</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="n">tag</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="k">if</span> <span class="n">dihedral_style</span> <span class="ow">and</span> <span class="n">dihedral_style</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;harm&#39;</span><span class="p">):</span>
                    <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">DihedralType</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span>
                                                      <span class="n">k</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                                                      <span class="n">d</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span>
                                                      <span class="n">n</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">3</span><span class="p">])))</span>
                <span class="k">elif</span> <span class="p">(</span><span class="n">dihedral_style</span> <span class="ow">and</span>
                        <span class="n">dihedral_style</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;class2&#39;</span><span class="p">)):</span>
                    <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">DihedralType</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span>
                                                      <span class="n">k1</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                                                      <span class="n">phi1</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span>
                                                      <span class="n">k2</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">3</span><span class="p">]),</span>
                                                      <span class="n">phi2</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">4</span><span class="p">]),</span>
                                                      <span class="n">k3</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">5</span><span class="p">]),</span>
                                                      <span class="n">phi3</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">6</span><span class="p">])))</span>
                <span class="k">elif</span> <span class="p">(</span><span class="n">dihedral_style</span> <span class="ow">and</span> <span class="n">dihedral_style</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;fourier&#39;</span><span class="p">)):</span>
                    <span class="n">data</span> <span class="o">=</span> <span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
                    <span class="n">m</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span>
                    <span class="n">k</span><span class="o">=</span><span class="p">[]</span>
                    <span class="n">d</span><span class="o">=</span><span class="p">[]</span>
                    <span class="n">n</span><span class="o">=</span><span class="p">[]</span>
                    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">m</span><span class="p">):</span>
                        <span class="n">k</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span>
                        <span class="n">n</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span>
                    <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">DihedralType</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span>
                                                      <span class="n">m</span><span class="o">=</span><span class="n">m</span><span class="p">,</span>
                                                      <span class="n">k</span><span class="o">=</span><span class="nb">map</span><span class="p">(</span><span class="nb">float</span><span class="p">,</span> <span class="n">k</span><span class="p">),</span>
                                                      <span class="n">d</span><span class="o">=</span><span class="nb">map</span><span class="p">(</span><span class="nb">float</span><span class="p">,</span> <span class="n">d</span><span class="p">),</span>
                                                      <span class="n">n</span><span class="o">=</span><span class="nb">map</span><span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="n">n</span><span class="p">)))</span>
                <span class="k">elif</span> <span class="ow">not</span> <span class="n">dihedral_style</span><span class="p">:</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span> <span class="ow">and</span> <span class="n">i</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                        <span class="n">warning_print</span><span class="p">(</span><span class="s1">&#39;dihedral_style currently unknown - &#39;</span>
                                      <span class="s1">&#39;guessing based on number of parameters &#39;</span>
                                      <span class="s1">&#39;(3=harmonic 6=class2 1+3n=fourier)&#39;</span><span class="p">)</span>
                    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">==</span> <span class="mi">4</span><span class="p">:</span>
                        <span class="n">dihedral_style</span> <span class="o">=</span> <span class="s1">&#39;harmonic&#39;</span>
                        <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">DihedralType</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span>
                                                          <span class="n">k</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                                                          <span class="n">d</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span>
                                                          <span class="n">n</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">3</span><span class="p">])))</span>
                    <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">==</span> <span class="mi">7</span><span class="p">:</span>
                        <span class="n">dihedral_style</span> <span class="o">=</span> <span class="s1">&#39;class2&#39;</span>
                        <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">DihedralType</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span>
                                                          <span class="n">k1</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                                                          <span class="n">phi1</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span>
                                                          <span class="n">k2</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">3</span><span class="p">]),</span>
                                                          <span class="n">phi2</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">4</span><span class="p">]),</span>
                                                          <span class="n">k3</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">5</span><span class="p">]),</span>
                                                          <span class="n">phi3</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">6</span><span class="p">])))</span>
                    <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">%</span> <span class="mi">3</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                        <span class="n">dihedral_style</span> <span class="o">=</span> <span class="s1">&#39;fourier&#39;</span>
                        <span class="n">data</span> <span class="o">=</span> <span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
                        <span class="n">m</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span>
                        <span class="n">k</span><span class="o">=</span><span class="p">[]</span>
                        <span class="n">n</span><span class="o">=</span><span class="p">[]</span>
                        <span class="n">d</span><span class="o">=</span><span class="p">[]</span>
                        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">m</span><span class="p">):</span>
                            <span class="n">k</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span>
                            <span class="n">n</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span>
                            <span class="n">d</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span>
                        <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">DihedralType</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span>
                                                          <span class="n">m</span><span class="o">=</span><span class="n">m</span><span class="p">,</span>
                                                          <span class="n">k</span><span class="o">=</span><span class="nb">map</span><span class="p">(</span><span class="nb">float</span><span class="p">,</span> <span class="n">k</span><span class="p">),</span>
                                                          <span class="n">d</span><span class="o">=</span><span class="nb">map</span><span class="p">(</span><span class="nb">float</span><span class="p">,</span> <span class="n">d</span><span class="p">),</span>
                                                          <span class="n">n</span><span class="o">=</span><span class="nb">map</span><span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="n">n</span><span class="p">)))</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span> <span class="ow">and</span> <span class="n">dihedral_style</span><span class="p">:</span>
                <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;read &quot;</span><span class="si">%s</span><span class="s1">&quot; dihedral parameters &#39;</span>
                              <span class="s1">&#39;for </span><span class="si">%s</span><span class="s1"> DihedralTypes&#39;</span>
                              <span class="o">%</span> <span class="p">(</span><span class="n">dihedral_style</span><span class="p">,</span> <span class="n">ndihedral_types</span><span class="p">))</span>
            <span class="k">elif</span> <span class="ow">not</span> <span class="n">quiet</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">dihedral_style</span><span class="p">:</span>
                <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;cannot determine dihedral_style - &#39;</span>
                              <span class="s1">&#39;skipping bond parameters&#39;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;MiddleBondTorsion&#39;</span><span class="p">:</span>
            <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">ndihedral_types</span><span class="p">):</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="n">tag</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">a1</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">a2</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">a3</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">r2</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">4</span><span class="p">])</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span> <span class="ow">and</span> <span class="n">dihedral_style</span><span class="p">:</span>
                <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;read &quot;</span><span class="si">%s</span><span class="s1">&quot; dihedral &#39;</span>
                              <span class="s1">&#39;(middle-bond-torsion parameters for &#39;</span>
                              <span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> DihedralTypes&#39;</span>
                              <span class="o">%</span> <span class="p">(</span><span class="n">dihedral_style</span><span class="p">,</span> <span class="n">ndihedral_types</span><span class="p">))</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;EndBondTorsion&#39;</span><span class="p">:</span>
            <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">ndihedral_types</span><span class="p">):</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="n">tag</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">b1</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">b2</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">b3</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">c1</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">4</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">c2</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">5</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">c3</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">6</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">r1</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">7</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">r3</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">8</span><span class="p">])</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span> <span class="ow">and</span> <span class="n">dihedral_style</span><span class="p">:</span>
                <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;read &quot;</span><span class="si">%s</span><span class="s1">&quot; dihedral &#39;</span>
                              <span class="s1">&#39;(end-bond-torsion parameters for &#39;</span>
                              <span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> DihedralTypes&#39;</span>
                              <span class="o">%</span> <span class="p">(</span><span class="n">dihedral_style</span><span class="p">,</span> <span class="n">ndihedral_types</span><span class="p">))</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;AngleTorsion&#39;</span><span class="p">:</span>
            <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">ndihedral_types</span><span class="p">):</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="n">tag</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">d1</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">d2</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">d3</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">e1</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">4</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">e2</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">5</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">e3</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">6</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">theta1</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">7</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">theta2</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">8</span><span class="p">])</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span> <span class="ow">and</span> <span class="n">dihedral_style</span><span class="p">:</span>
                    <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;read &quot;</span><span class="si">%s</span><span class="s1">&quot; dihedral &#39;</span>
                                  <span class="s1">&#39;(angle-torsion parameters for &#39;</span>
                                  <span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> DihedralTypes&#39;</span>
                                  <span class="o">%</span> <span class="p">(</span><span class="n">dihedral_style</span><span class="p">,</span> <span class="n">ndihedral_types</span><span class="p">))</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;AngleAngleTorsion&#39;</span><span class="p">:</span>
            <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">ndihedral_types</span><span class="p">):</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="n">tag</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">m</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span> <span class="ow">and</span> <span class="n">dihedral_style</span><span class="p">:</span>
                <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;read &quot;</span><span class="si">%s</span><span class="s1">&quot; dihedral &#39;</span>
                              <span class="s1">&#39;(angle-angle-torsion parameters for &#39;</span>
                              <span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> DihedralTypes&#39;</span>
                              <span class="o">%</span> <span class="p">(</span><span class="n">dihedral_style</span><span class="p">,</span> <span class="n">ndihedral_types</span><span class="p">))</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;BondBond13&#39;</span><span class="p">:</span>
            <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">ndihedral_types</span><span class="p">):</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="n">tag</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">n_class2</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span> <span class="ow">and</span> <span class="n">dihedral_style</span><span class="p">:</span>
                <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;read &quot;</span><span class="si">%s</span><span class="s1">&quot; dihedral &#39;</span>
                              <span class="s1">&#39;(bond-bond-1-3 parameters for &#39;</span>
                              <span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> DihedralTypes&#39;</span>
                              <span class="o">%</span> <span class="p">(</span><span class="n">dihedral_style</span><span class="p">,</span> <span class="n">ndihedral_types</span><span class="p">))</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;Improper&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="s1">&#39;#&#39;</span> <span class="ow">in</span> <span class="n">line</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">improper_style</span><span class="p">:</span>
                <span class="n">line</span> <span class="o">=</span> <span class="s1">&#39; &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">line</span><span class="p">)</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;#&#39;</span><span class="p">)</span>
                <span class="n">improper_style</span> <span class="o">=</span> <span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
            <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nimproper_types</span><span class="p">):</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;#&#39;</span><span class="p">)</span>
                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                    <span class="n">line</span><span class="p">,</span> <span class="n">name</span> <span class="o">=</span> <span class="n">line</span>
                    <span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;,&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">re</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;,|\s+&#39;</span><span class="p">,</span> <span class="n">name</span><span class="o">.</span><span class="n">strip</span><span class="p">()))</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">line</span> <span class="o">=</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                    <span class="n">name</span> <span class="o">=</span> <span class="bp">None</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="n">tag</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="k">if</span> <span class="n">improper_style</span> <span class="ow">and</span> <span class="n">improper_style</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;harm&#39;</span><span class="p">):</span>
                    <span class="n">s</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">ImproperType</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span>
                                                      <span class="n">k</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                                                      <span class="n">x0</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">])))</span>
                <span class="k">elif</span> <span class="p">(</span><span class="n">improper_style</span> <span class="ow">and</span>
                      <span class="n">improper_style</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;class2&#39;</span><span class="p">)):</span>
                    <span class="n">s</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">ImproperType</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span>
                                                      <span class="n">k</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                                                      <span class="n">x0</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">])))</span>
                <span class="k">elif</span> <span class="p">(</span><span class="n">improper_style</span> <span class="ow">and</span>
                      <span class="n">improper_style</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;cvff&#39;</span><span class="p">)):</span>
                    <span class="n">s</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">ImproperType</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span>
                                                      <span class="n">k</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                                                      <span class="n">d</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span>
                                                      <span class="n">n</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">3</span><span class="p">])))</span>
                <span class="k">elif</span> <span class="ow">not</span> <span class="n">improper_style</span><span class="p">:</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span> <span class="ow">and</span> <span class="n">i</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                            <span class="n">warning_print</span><span class="p">(</span><span class="s1">&#39;cannot guess improper_style &#39;</span>
                                          <span class="s1">&#39;from number of parameters - &#39;</span>
                                          <span class="s1">&#39;will try to determine style later &#39;</span>
                                          <span class="s1">&#39;based on other types&#39;</span><span class="p">)</span>
                    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
                        <span class="n">s</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">ImproperType</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span>
                                                          <span class="n">k</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                                                          <span class="n">x0</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">])))</span>
                    <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">==</span> <span class="mi">4</span><span class="p">:</span>
                        <span class="n">improper_style</span> <span class="o">=</span> <span class="s1">&#39;cvff&#39;</span>
                        <span class="n">s</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">ImproperType</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span>
                                                          <span class="n">k</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                                                          <span class="n">d</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span>
                                                          <span class="n">n</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">3</span><span class="p">])))</span>

            <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span> <span class="ow">and</span> <span class="n">improper_style</span><span class="p">:</span>
                <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;read &quot;</span><span class="si">%s</span><span class="s1">&quot; improper parameters &#39;</span>
                              <span class="s1">&#39;for </span><span class="si">%s</span><span class="s1"> ImproperTypes&#39;</span>
                              <span class="o">%</span> <span class="p">(</span><span class="n">improper_style</span><span class="p">,</span> <span class="n">nimproper_types</span><span class="p">))</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;AngleAngle&#39;</span><span class="p">:</span>
            <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nimproper_types</span><span class="p">):</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="n">tag</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">improper_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">m1</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">improper_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">m2</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">improper_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">m3</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">improper_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">theta1</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">4</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">improper_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">theta2</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">5</span><span class="p">])</span>
                <span class="n">s</span><span class="o">.</span><span class="n">improper_types</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span><span class="o">.</span><span class="n">theta3</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">6</span><span class="p">])</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span> <span class="ow">and</span> <span class="n">improper_style</span><span class="p">:</span>
                <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;read &quot;</span><span class="si">%s</span><span class="s1">&quot; improper &#39;</span>
                              <span class="s1">&#39;(angle-angle parameters for &#39;</span>
                              <span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> ImproperTypes&#39;</span>
                              <span class="o">%</span> <span class="p">(</span><span class="n">improper_style</span><span class="p">,</span> <span class="n">nimproper_types</span><span class="p">))</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;Atoms&#39;</span><span class="p">:</span>
            <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nparticles</span><span class="p">):</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="n">tag</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">atom_style</span><span class="p">:</span>
                    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">==</span> <span class="mi">7</span><span class="p">:</span>
                        <span class="n">atom_style</span> <span class="o">=</span> <span class="s1">&#39;full&#39;</span>
                    <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">==</span> <span class="mi">6</span><span class="p">:</span>
                        <span class="k">try</span><span class="p">:</span>
                            <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
                            <span class="n">atom_style</span> <span class="o">=</span> <span class="s1">&#39;molecular&#39;</span>
                        <span class="k">except</span><span class="p">:</span>
                            <span class="n">atom_style</span> <span class="o">=</span> <span class="s1">&#39;charge&#39;</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">warning_print</span><span class="p">(</span><span class="s1">&#39;cannot determine atom_style; assuming atom_style &quot;full&quot;&#39;</span><span class="p">)</span>
                        <span class="n">atom_style</span> <span class="o">=</span> <span class="s1">&#39;full&#39;</span>
                <span class="k">if</span> <span class="n">atom_style</span> <span class="o">==</span> <span class="s1">&#39;full&#39;</span><span class="p">:</span>
                    <span class="n">d_</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;tag&#39;</span><span class="p">:</span> <span class="n">tag</span><span class="p">,</span> <span class="s1">&#39;molecule&#39;</span><span class="p">:</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span> <span class="s1">&#39;type&#39;</span><span class="p">:</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span>
                          <span class="s1">&#39;charge&#39;</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">3</span><span class="p">]),</span> <span class="s1">&#39;x&#39;</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">4</span><span class="p">]),</span>
                          <span class="s1">&#39;y&#39;</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">5</span><span class="p">]),</span> <span class="s1">&#39;z&#39;</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">6</span><span class="p">])}</span>
                <span class="k">elif</span> <span class="n">atom_style</span> <span class="o">==</span> <span class="s1">&#39;charge&#39;</span><span class="p">:</span>
                    <span class="n">d_</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;tag&#39;</span><span class="p">:</span> <span class="n">tag</span><span class="p">,</span> <span class="s1">&#39;molecule&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="s1">&#39;type&#39;</span><span class="p">:</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                          <span class="s1">&#39;charge&#39;</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span> <span class="s1">&#39;x&#39;</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">3</span><span class="p">]),</span>
                          <span class="s1">&#39;y&#39;</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">4</span><span class="p">]),</span> <span class="s1">&#39;z&#39;</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">5</span><span class="p">])}</span>
                <span class="k">elif</span> <span class="n">atom_style</span> <span class="o">==</span> <span class="s1">&#39;molecular&#39;</span><span class="p">:</span>
                    <span class="n">d_</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;tag&#39;</span><span class="p">:</span> <span class="n">tag</span><span class="p">,</span> <span class="s1">&#39;molecule&#39;</span><span class="p">:</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span> <span class="s1">&#39;type&#39;</span><span class="p">:</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span>
                          <span class="s1">&#39;charge&#39;</span><span class="p">:</span> <span class="mf">0.</span><span class="p">,</span> <span class="s1">&#39;x&#39;</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">3</span><span class="p">]),</span> <span class="s1">&#39;y&#39;</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">4</span><span class="p">]),</span> <span class="s1">&#39;z&#39;</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">5</span><span class="p">])}</span>
                <span class="k">if</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">tag</span><span class="p">]:</span>
                    <span class="n">p</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="o">**</span><span class="n">d_</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">p</span> <span class="o">=</span> <span class="n">Particle</span><span class="p">(</span><span class="n">vx</span><span class="o">=</span><span class="mf">0.</span><span class="p">,</span> <span class="n">vy</span><span class="o">=</span><span class="mf">0.</span><span class="p">,</span> <span class="n">vz</span><span class="o">=</span><span class="mf">0.</span><span class="p">,</span> <span class="o">**</span><span class="n">d_</span><span class="p">)</span>
                    <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">s</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">check</span><span class="p">():</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">frac_x</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">x</span> <span class="o">/</span> <span class="n">s</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dx</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">frac_y</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span> <span class="o">/</span> <span class="n">s</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dy</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">frac_z</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">z</span> <span class="o">/</span> <span class="n">s</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dz</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span><span class="p">:</span>
                <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;read </span><span class="si">%s</span><span class="s1"> particles&#39;</span> <span class="o">%</span> <span class="n">nparticles</span><span class="p">)</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;Velocities&#39;</span><span class="p">:</span>
            <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nparticles</span><span class="p">):</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="n">tag</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="k">if</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">tag</span><span class="p">]:</span>
                    <span class="n">p</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">tag</span><span class="p">]</span>
                    <span class="n">d_</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;vx&#39;</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span> <span class="s1">&#39;vy&#39;</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span>
                          <span class="s1">&#39;vz&#39;</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">3</span><span class="p">])}</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="o">**</span><span class="n">d_</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">p</span> <span class="o">=</span> <span class="n">Particle</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="n">vx</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span> <span class="n">vy</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span>
                                 <span class="n">vz</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">3</span><span class="p">]))</span>
                    <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span><span class="p">:</span>
                <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;read velocities for </span><span class="si">%s</span><span class="s1"> particles&#39;</span> <span class="o">%</span> <span class="n">nparticles</span><span class="p">)</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;Bonds&#39;</span><span class="p">:</span>
            <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nbonds</span><span class="p">):</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="n">tag</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="n">b</span> <span class="o">=</span> <span class="n">Bond</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                         <span class="n">a</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span> <span class="n">b</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">3</span><span class="p">]))</span>
                <span class="n">s</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">b</span><span class="p">)</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span><span class="p">:</span>
                <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;read </span><span class="si">%s</span><span class="s1"> bonds&#39;</span> <span class="o">%</span> <span class="n">nbonds</span><span class="p">)</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;Angles&#39;</span><span class="p">:</span>
            <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nangles</span><span class="p">):</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="n">tag</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="n">a</span> <span class="o">=</span> <span class="n">Angle</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                          <span class="n">a</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span> <span class="n">b</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">3</span><span class="p">]),</span> <span class="n">c</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">4</span><span class="p">]))</span>
                <span class="n">s</span><span class="o">.</span><span class="n">angles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span><span class="p">:</span>
                <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;read </span><span class="si">%s</span><span class="s1"> angles&#39;</span> <span class="o">%</span> <span class="n">nangles</span><span class="p">)</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;Dihedrals&#39;</span><span class="p">:</span>
            <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">ndihedrals</span><span class="p">):</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="n">tag</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="n">d</span> <span class="o">=</span> <span class="n">Dihedral</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                             <span class="n">a</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span> <span class="n">b</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">3</span><span class="p">]),</span>
                             <span class="n">c</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">4</span><span class="p">]),</span> <span class="n">d</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">5</span><span class="p">]))</span>
                <span class="n">s</span><span class="o">.</span><span class="n">dihedrals</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span><span class="p">:</span>
                <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;read </span><span class="si">%s</span><span class="s1"> dihedrals&#39;</span> <span class="o">%</span> <span class="n">ndihedrals</span><span class="p">)</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;Impropers&#39;</span><span class="p">:</span>
            <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nimpropers</span><span class="p">):</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="n">tag</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">ff_class</span> <span class="o">==</span> <span class="s1">&#39;2&#39;</span> <span class="ow">or</span> <span class="n">improper_style</span> <span class="o">==</span> <span class="s1">&#39;class2&#39;</span> <span class="ow">or</span> <span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">improper_types</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="ow">and</span> <span class="n">s</span><span class="o">.</span><span class="n">improper_types</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">m1</span>
                        <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">)):</span>
                    <span class="n">s</span><span class="o">.</span><span class="n">impropers</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">Improper</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                                             <span class="n">a</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">3</span><span class="p">]),</span> <span class="n">b</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span>
                                             <span class="n">c</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">4</span><span class="p">]),</span> <span class="n">d</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">5</span><span class="p">])))</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">s</span><span class="o">.</span><span class="n">impropers</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">Improper</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                                             <span class="n">a</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span> <span class="n">b</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">3</span><span class="p">]),</span>
                                             <span class="n">c</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">4</span><span class="p">]),</span> <span class="n">d</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">5</span><span class="p">])))</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span><span class="p">:</span>
                <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;read </span><span class="si">%s</span><span class="s1"> impropers&#39;</span> <span class="o">%</span> <span class="n">nimpropers</span><span class="p">)</span>
    <span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

    <span class="n">s</span><span class="o">.</span><span class="n">atom_style</span> <span class="o">=</span> <span class="n">atom_style</span>
    <span class="n">s</span><span class="o">.</span><span class="n">pair_style</span> <span class="o">=</span> <span class="n">pair_style</span>
    <span class="n">s</span><span class="o">.</span><span class="n">bond_style</span> <span class="o">=</span> <span class="n">bond_style</span>
    <span class="n">s</span><span class="o">.</span><span class="n">angle_style</span> <span class="o">=</span> <span class="n">angle_style</span>
    <span class="n">s</span><span class="o">.</span><span class="n">dihedral_style</span> <span class="o">=</span> <span class="n">dihedral_style</span>
    <span class="k">if</span> <span class="n">improper_style</span><span class="p">:</span>
        <span class="n">s</span><span class="o">.</span><span class="n">improper_style</span> <span class="o">=</span> <span class="n">improper_style</span>
    <span class="k">elif</span> <span class="ow">not</span> <span class="n">improper_style</span> <span class="ow">and</span> <span class="n">s</span><span class="o">.</span><span class="n">impropers</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span><span class="p">:</span>
            <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;improper style not set explicitly &#39;</span>
                          <span class="s1">&#39;but impropers exist in system, guessing style &#39;</span>
                          <span class="s1">&#39;based on other forcefield styles...&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">bond_style</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;harm&#39;</span><span class="p">)</span> <span class="ow">or</span>
                <span class="n">s</span><span class="o">.</span><span class="n">angle_style</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;harm&#39;</span><span class="p">)</span> <span class="ow">or</span>
                <span class="n">s</span><span class="o">.</span><span class="n">dihedral_style</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;harm&#39;</span><span class="p">)):</span>
            <span class="n">improper_style</span> <span class="o">=</span> <span class="s1">&#39;harmonic&#39;</span>
            <span class="n">s</span><span class="o">.</span><span class="n">improper_style</span> <span class="o">=</span> <span class="s1">&#39;harmonic&#39;</span>
        <span class="k">elif</span> <span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">bond_style</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;class2&#39;</span><span class="p">)</span> <span class="ow">or</span>
                <span class="n">s</span><span class="o">.</span><span class="n">angle_style</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;class2&#39;</span><span class="p">)</span> <span class="ow">or</span>
                <span class="n">s</span><span class="o">.</span><span class="n">dihedral_style</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;class2&#39;</span><span class="p">)):</span>
            <span class="n">improper_style</span> <span class="o">=</span> <span class="s1">&#39;class2&#39;</span>
            <span class="n">s</span><span class="o">.</span><span class="n">improper_style</span> <span class="o">=</span> <span class="s1">&#39;class2&#39;</span>
        <span class="k">if</span> <span class="n">s</span><span class="o">.</span><span class="n">improper_style</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span><span class="p">:</span>
                <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;setting improper style to &quot;</span><span class="si">%s</span><span class="s1">&quot;, &#39;</span>
                              <span class="s1">&#39;if this is incorrect try explicitly setting &#39;</span>
                              <span class="s1">&#39;improper_style as argument in &#39;</span>
                              <span class="s1">&#39;pysimm.system.read_lammps&#39;</span> <span class="o">%</span> <span class="n">improper_style</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span><span class="p">:</span>
                <span class="n">error_print</span><span class="p">(</span><span class="s1">&#39;still cannot determine improper style...&#39;</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">pair_style</span> <span class="ow">and</span> <span class="n">pair_style</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;lj&#39;</span><span class="p">):</span>
        <span class="k">if</span> <span class="p">((</span><span class="n">s</span><span class="o">.</span><span class="n">bond_style</span> <span class="ow">and</span> <span class="n">s</span><span class="o">.</span><span class="n">bond_style</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;class2&#39;</span><span class="p">))</span> <span class="ow">or</span>
                <span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">angle_style</span> <span class="ow">and</span> <span class="n">s</span><span class="o">.</span><span class="n">angle_style</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;class2&#39;</span><span class="p">))</span> <span class="ow">or</span>
                <span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">dihedral_style</span> <span class="ow">and</span> <span class="n">s</span><span class="o">.</span><span class="n">dihedral_style</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;class2&#39;</span><span class="p">))):</span>
            <span class="n">s</span><span class="o">.</span><span class="n">pair_style</span> <span class="o">=</span> <span class="s1">&#39;class2&#39;</span>

    <span class="n">styles</span> <span class="o">=</span> <span class="p">[</span><span class="n">s</span><span class="o">.</span><span class="n">pair_style</span><span class="p">,</span> <span class="n">s</span><span class="o">.</span><span class="n">bond_style</span><span class="p">,</span> <span class="n">s</span><span class="o">.</span><span class="n">angle_style</span><span class="p">,</span> <span class="n">s</span><span class="o">.</span><span class="n">dihedral_style</span><span class="p">,</span>
              <span class="n">s</span><span class="o">.</span><span class="n">improper_style</span><span class="p">]</span>
    <span class="k">if</span> <span class="s1">&#39;class2&#39;</span> <span class="ow">in</span> <span class="n">styles</span><span class="p">:</span>
        <span class="n">s</span><span class="o">.</span><span class="n">ff_class</span> <span class="o">=</span> <span class="s1">&#39;2&#39;</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">s</span><span class="o">.</span><span class="n">ff_class</span> <span class="o">=</span> <span class="s1">&#39;1&#39;</span>

    <span class="k">if</span> <span class="s1">&#39;harmonic&#39;</span> <span class="ow">in</span> <span class="n">styles</span> <span class="ow">and</span> <span class="s1">&#39;class2&#39;</span> <span class="ow">in</span> <span class="n">styles</span><span class="p">:</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span><span class="p">:</span>
            <span class="n">warning_print</span><span class="p">(</span><span class="s1">&#39;it appears there is a mixture of class1 and class2 &#39;</span>
                          <span class="s1">&#39;forcefield styles in your system...this is usually &#39;</span>
                          <span class="s1">&#39;unadvised&#39;</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">set_types</span><span class="p">:</span>
        <span class="n">s</span><span class="o">.</span><span class="n">objectify</span><span class="p">()</span>

    <span class="k">for</span> <span class="n">pt</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">particle_types</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">pt</span><span class="o">.</span><span class="n">name</span> <span class="ow">and</span> <span class="n">pt</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s1">&#39;@&#39;</span><span class="p">)</span> <span class="o">&gt;=</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">pt</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;@&#39;</span><span class="p">)[</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;H&#39;</span><span class="p">,</span> <span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;N&#39;</span><span class="p">,</span> <span class="s1">&#39;O&#39;</span><span class="p">,</span> <span class="s1">&#39;F&#39;</span><span class="p">,</span> <span class="s1">&#39;S&#39;</span><span class="p">]:</span>
                <span class="n">pt</span><span class="o">.</span><span class="n">elem</span> <span class="o">=</span> <span class="n">pt</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;@&#39;</span><span class="p">)[</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">pt</span><span class="o">.</span><span class="n">name</span> <span class="ow">and</span> <span class="n">pt</span><span class="o">.</span><span class="n">name</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;L&#39;</span> <span class="ow">and</span> <span class="n">pt</span><span class="o">.</span><span class="n">name</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">!=</span> <span class="s1">&#39;i&#39;</span><span class="p">:</span>
            <span class="n">pt</span><span class="o">.</span><span class="n">elem</span> <span class="o">=</span> <span class="n">pt</span><span class="o">.</span><span class="n">name</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span>
        <span class="k">elif</span> <span class="n">pt</span><span class="o">.</span><span class="n">name</span><span class="p">:</span>
            <span class="n">pt</span><span class="o">.</span><span class="n">elem</span> <span class="o">=</span> <span class="n">pt</span><span class="o">.</span><span class="n">name</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">2</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">pt</span><span class="o">.</span><span class="n">name</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="mi">3</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;Na&#39;</span><span class="p">:</span>
                <span class="n">pt</span><span class="o">.</span><span class="n">elem</span> <span class="o">=</span> <span class="s1">&#39;Na&#39;</span>
            <span class="k">if</span> <span class="n">pt</span><span class="o">.</span><span class="n">name</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;H&#39;</span><span class="p">,</span> <span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;N&#39;</span><span class="p">,</span> <span class="s1">&#39;O&#39;</span><span class="p">,</span> <span class="s1">&#39;F&#39;</span><span class="p">,</span> <span class="s1">&#39;S&#39;</span><span class="p">]:</span>
                <span class="n">pt</span><span class="o">.</span><span class="n">elem</span> <span class="o">=</span> <span class="n">pt</span><span class="o">.</span><span class="n">name</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span>

    <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="n">ParticleType</span><span class="p">)</span> <span class="ow">and</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span> <span class="ow">and</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s1">&#39;@&#39;</span><span class="p">)</span> <span class="o">&gt;=</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;H&#39;</span><span class="p">:</span>
                <span class="n">p</span><span class="o">.</span><span class="n">linker</span> <span class="o">=</span> <span class="s1">&#39;head&#39;</span>
            <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;T&#39;</span><span class="p">:</span>
                <span class="n">p</span><span class="o">.</span><span class="n">linker</span> <span class="o">=</span> <span class="s1">&#39;tail&#39;</span>
            <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;L&#39;</span><span class="p">:</span>
                <span class="n">p</span><span class="o">.</span><span class="n">linker</span> <span class="o">=</span> <span class="bp">True</span>

    <span class="k">if</span> <span class="n">s</span><span class="o">.</span><span class="n">objectified</span><span class="p">:</span>
        <span class="n">s</span><span class="o">.</span><span class="n">set_cog</span><span class="p">()</span>
        <span class="n">s</span><span class="o">.</span><span class="n">set_mass</span><span class="p">()</span>
        <span class="n">s</span><span class="o">.</span><span class="n">set_volume</span><span class="p">()</span>
        <span class="n">s</span><span class="o">.</span><span class="n">set_density</span><span class="p">()</span>
        <span class="n">s</span><span class="o">.</span><span class="n">set_velocity</span><span class="p">()</span>

    <span class="k">return</span> <span class="n">s</span></div>


<div class="viewcode-block" id="read_pubchem_smiles"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.read_pubchem_smiles">[docs]</a><span class="k">def</span> <span class="nf">read_pubchem_smiles</span><span class="p">(</span><span class="n">smiles</span><span class="p">,</span> <span class="n">quiet</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">type_with</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.system.read_pubchem_smiles</span>

<span class="sd">    Interface with pubchem restful API to create molecular system from SMILES format</span>

<span class="sd">    Args:</span>
<span class="sd">        smiles: smiles formatted string of molecule</span>
<span class="sd">        type_with: :class:`~pysimm.forcefield.Forcefield` object to type with default=None</span>

<span class="sd">    Returns:</span>
<span class="sd">        :class:`~pysimm.system.System` object</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">req</span> <span class="o">=</span> <span class="p">(</span><span class="s1">&#39;https://pubchem.ncbi.nlm.nih.gov/&#39;</span>
           <span class="s1">&#39;rest/pug/compound/smiles/</span><span class="si">%s</span><span class="s1">/SDF/?record_type=3d&#39;</span> <span class="o">%</span> <span class="n">smiles</span><span class="p">)</span>
           
    <span class="k">if</span> <span class="ow">not</span> <span class="n">quiet</span><span class="p">:</span>
        <span class="k">print</span><span class="p">(</span><span class="s1">&#39;making request to pubchem RESTful API:&#39;</span><span class="p">)</span>
        <span class="k">print</span><span class="p">(</span><span class="n">req</span><span class="p">)</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">resp</span> <span class="o">=</span> <span class="n">urlopen</span><span class="p">(</span><span class="n">req</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">read_mol</span><span class="p">(</span><span class="n">resp</span><span class="o">.</span><span class="n">read</span><span class="p">(),</span> <span class="n">type_with</span><span class="o">=</span><span class="n">type_with</span><span class="p">)</span>
    <span class="k">except</span> <span class="n">HTTPError</span><span class="p">,</span> <span class="n">URLError</span><span class="p">:</span>
        <span class="k">print</span><span class="p">(</span><span class="s1">&#39;Could not retrieve pubchem entry for smiles </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">smiles</span><span class="p">)</span></div>
        
        
<div class="viewcode-block" id="read_pubchem_cid"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.read_pubchem_cid">[docs]</a><span class="k">def</span> <span class="nf">read_pubchem_cid</span><span class="p">(</span><span class="n">cid</span><span class="p">,</span> <span class="n">type_with</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.system.read_pubchem_smiles</span>

<span class="sd">    Interface with pubchem restful API to create molecular system from SMILES format</span>

<span class="sd">    Args:</span>
<span class="sd">        smiles: smiles formatted string of molecule</span>
<span class="sd">        type_with: :class:`~pysimm.forcefield.Forcefield` object to type with default=None</span>

<span class="sd">    Returns:</span>
<span class="sd">        :class:`~pysimm.system.System` object</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">req</span> <span class="o">=</span> <span class="p">(</span><span class="s1">&#39;https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/cid/{}/SDF/?record_type=3d&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">cid</span><span class="p">))</span>
           
    <span class="k">print</span><span class="p">(</span><span class="s1">&#39;making request to pubchem RESTful API:&#39;</span><span class="p">)</span>
    <span class="k">print</span><span class="p">(</span><span class="n">req</span><span class="p">)</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">resp</span> <span class="o">=</span> <span class="n">urlopen</span><span class="p">(</span><span class="n">req</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">read_mol</span><span class="p">(</span><span class="n">resp</span><span class="o">.</span><span class="n">read</span><span class="p">(),</span> <span class="n">type_with</span><span class="o">=</span><span class="n">type_with</span><span class="p">)</span>
    <span class="k">except</span> <span class="n">HTTPError</span><span class="p">,</span> <span class="n">URLError</span><span class="p">:</span>
        <span class="k">print</span><span class="p">(</span><span class="s1">&#39;Could not retrieve pubchem entry for cid </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">cid</span><span class="p">)</span></div>


<div class="viewcode-block" id="read_cml"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.read_cml">[docs]</a><span class="k">def</span> <span class="nf">read_cml</span><span class="p">(</span><span class="n">cml_file</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.system.read_cml</span>

<span class="sd">    Interprets cml file and creates :class:`~pysimm.system.System` object</span>

<span class="sd">    Args:</span>
<span class="sd">        cml_file: cml file name</span>
<span class="sd">        linkers (optional): if True, use spinMultiplicity to determine linker default=None</span>

<span class="sd">    Returns:</span>
<span class="sd">        :class:`~pysimm.system.System` object</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">linkers</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;linkers&#39;</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="n">cml_file</span><span class="p">):</span>
        <span class="n">debug_print</span><span class="p">(</span><span class="s1">&#39;reading file&#39;</span><span class="p">)</span>
        <span class="n">iter_parse</span> <span class="o">=</span> <span class="n">Et</span><span class="o">.</span><span class="n">iterparse</span><span class="p">(</span><span class="n">cml_file</span><span class="p">)</span>
    <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">cml_file</span><span class="p">,</span> <span class="nb">basestring</span><span class="p">):</span>
        <span class="n">debug_print</span><span class="p">(</span><span class="s1">&#39;reading string&#39;</span><span class="p">)</span>
        <span class="n">iter_parse</span> <span class="o">=</span> <span class="n">Et</span><span class="o">.</span><span class="n">iterparse</span><span class="p">(</span><span class="n">StringIO</span><span class="p">(</span><span class="n">cml_file</span><span class="p">))</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">raise</span> <span class="n">PysimmError</span><span class="p">(</span><span class="s1">&#39;pysimm.system.read_cml requires a file as argument&#39;</span><span class="p">)</span>

    <span class="k">for</span> <span class="n">_</span><span class="p">,</span> <span class="n">el</span> <span class="ow">in</span> <span class="n">iter_parse</span><span class="p">:</span>
        <span class="k">if</span> <span class="s1">&#39;}&#39;</span> <span class="ow">in</span> <span class="n">el</span><span class="o">.</span><span class="n">tag</span><span class="p">:</span>
            <span class="n">el</span><span class="o">.</span><span class="n">tag</span> <span class="o">=</span> <span class="n">el</span><span class="o">.</span><span class="n">tag</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;}&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span>
    <span class="n">root</span> <span class="o">=</span> <span class="n">iter_parse</span><span class="o">.</span><span class="n">root</span>

    <span class="n">s</span> <span class="o">=</span> <span class="n">System</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;read using pysimm.system.read_cml&#39;</span><span class="p">)</span>

    <span class="n">particles</span> <span class="o">=</span> <span class="n">root</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s1">&#39;atomArray&#39;</span><span class="p">)</span>
    <span class="n">bonds</span> <span class="o">=</span> <span class="n">root</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s1">&#39;bondArray&#39;</span><span class="p">)</span>

    <span class="k">for</span> <span class="n">p_</span> <span class="ow">in</span> <span class="n">particles</span><span class="p">:</span>
        <span class="n">tag</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">p_</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s1">&#39;id&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">&#39;,&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">))</span>
        <span class="n">elem</span> <span class="o">=</span> <span class="n">p_</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s1">&#39;elementType&#39;</span><span class="p">]</span>
        <span class="n">x</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">p_</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s1">&#39;x3&#39;</span><span class="p">])</span>
        <span class="n">y</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">p_</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s1">&#39;y3&#39;</span><span class="p">])</span>
        <span class="n">z</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">p_</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s1">&#39;z3&#39;</span><span class="p">])</span>
        <span class="k">if</span> <span class="n">linkers</span><span class="p">:</span>
            <span class="n">linker</span> <span class="o">=</span> <span class="bp">True</span> <span class="k">if</span> <span class="n">p_</span><span class="o">.</span><span class="n">attrib</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;spinMultiplicity&#39;</span><span class="p">)</span> <span class="k">else</span> <span class="bp">None</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">linker</span> <span class="o">=</span> <span class="bp">None</span>

        <span class="n">p</span> <span class="o">=</span> <span class="n">Particle</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="n">elem</span><span class="o">=</span><span class="n">elem</span><span class="p">,</span> <span class="n">x</span><span class="o">=</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="o">=</span><span class="n">z</span><span class="p">,</span> <span class="n">charge</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">molecule</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">linker</span><span class="o">=</span><span class="n">linker</span><span class="p">)</span>
        <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>

    <span class="k">for</span> <span class="n">b_</span> <span class="ow">in</span> <span class="n">bonds</span><span class="p">:</span>
        <span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="n">b_</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s1">&#39;atomRefs2&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
        <span class="n">a</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">&#39;,&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">))</span>
        <span class="n">b</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">&#39;,&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">))</span>
        <span class="n">order</span> <span class="o">=</span> <span class="n">b_</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s1">&#39;order&#39;</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">order</span> <span class="o">==</span> <span class="s1">&#39;A&#39;</span><span class="p">:</span>
            <span class="n">order</span> <span class="o">=</span> <span class="mi">4</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">order</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">order</span><span class="p">)</span>

        <span class="n">b</span> <span class="o">=</span> <span class="n">Bond</span><span class="p">(</span><span class="n">a</span><span class="o">=</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="n">b</span><span class="p">,</span> <span class="n">order</span><span class="o">=</span><span class="n">order</span><span class="p">)</span>
        <span class="n">s</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">b</span><span class="p">)</span>

    <span class="n">s</span><span class="o">.</span><span class="n">objectify</span><span class="p">()</span>

    <span class="k">return</span> <span class="n">s</span></div>


<div class="viewcode-block" id="read_mol"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.read_mol">[docs]</a><span class="k">def</span> <span class="nf">read_mol</span><span class="p">(</span><span class="n">mol_file</span><span class="p">,</span> <span class="n">type_with</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">version</span><span class="o">=</span><span class="s1">&#39;V2000&#39;</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.system.read_mol</span>

<span class="sd">    Interprets mol file and creates :class:`~pysimm.system.System` object</span>

<span class="sd">    Args:</span>
<span class="sd">        mol_file: mol file name</span>
<span class="sd">        f (optional): :class:`~pysimm.forcefield.Forcefield` object to get data from</span>
<span class="sd">        version: version of mol file to expect default=&#39;V2000&#39;</span>

<span class="sd">    Returns:</span>
<span class="sd">        :class:`~pysimm.system.System` object</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="n">mol_file</span><span class="p">):</span>
        <span class="n">debug_print</span><span class="p">(</span><span class="s1">&#39;reading file&#39;</span><span class="p">)</span>
        <span class="n">f</span> <span class="o">=</span> <span class="nb">file</span><span class="p">(</span><span class="n">mol_file</span><span class="p">)</span>
    <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">mol_file</span><span class="p">,</span> <span class="nb">basestring</span><span class="p">):</span>
        <span class="n">debug_print</span><span class="p">(</span><span class="s1">&#39;reading string&#39;</span><span class="p">)</span>
        <span class="n">f</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">(</span><span class="n">mol_file</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">raise</span> <span class="n">PysimmError</span><span class="p">(</span><span class="s1">&#39;pysimm.system.read_mol requires either &#39;</span>
                          <span class="s1">&#39;file or string as argument&#39;</span><span class="p">)</span>

    <span class="n">s</span> <span class="o">=</span> <span class="n">System</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;read using pysimm.system.read_mol&#39;</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">):</span>
        <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>

    <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>

    <span class="n">nparticles</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">0</span><span class="p">])</span>
    <span class="n">nbonds</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">])</span>
    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">())</span> <span class="o">&gt;=</span> <span class="mi">3</span><span class="p">:</span>
        <span class="n">version</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>

    <span class="k">if</span> <span class="n">version</span> <span class="o">==</span> <span class="s1">&#39;V2000&#39;</span><span class="p">:</span>
        <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nparticles</span><span class="p">):</span>
            <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
            <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="n">elem</span><span class="p">,</span> <span class="n">something</span><span class="p">,</span> <span class="n">charge</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[:</span><span class="mi">6</span><span class="p">]</span>
            <span class="n">p</span> <span class="o">=</span> <span class="n">Particle</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">y</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">y</span><span class="p">),</span> <span class="n">z</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">z</span><span class="p">),</span> <span class="n">molecule</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                         <span class="n">elem</span><span class="o">=</span><span class="n">elem</span><span class="p">,</span> <span class="n">charge</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">charge</span><span class="p">))</span>
            <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">elem</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;L&#39;</span><span class="p">:</span>
                <span class="n">p</span><span class="o">.</span><span class="n">linker</span> <span class="o">=</span> <span class="bp">True</span>
                <span class="n">p</span><span class="o">.</span><span class="n">elem</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">elem</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
            <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">charge</span> <span class="o">==</span> <span class="mi">5</span><span class="p">:</span>
                <span class="n">p</span><span class="o">.</span><span class="n">linker</span> <span class="o">=</span> <span class="bp">True</span>
                <span class="n">p</span><span class="o">.</span><span class="n">charge</span> <span class="o">=</span> <span class="mi">0</span>

        <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nbonds</span><span class="p">):</span>
            <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
            <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">order</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[:</span><span class="mi">3</span><span class="p">])</span>
            <span class="n">new_bond</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">Bond</span><span class="p">(</span><span class="n">a</span><span class="o">=</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="n">b</span><span class="p">,</span> <span class="n">order</span><span class="o">=</span><span class="n">order</span><span class="p">))</span>

    <span class="k">elif</span> <span class="n">version</span> <span class="o">==</span> <span class="s1">&#39;V3000&#39;</span><span class="p">:</span>
        <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
        <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
        <span class="n">nparticles</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">3</span><span class="p">])</span>
        <span class="n">nbonds</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">4</span><span class="p">])</span>
        <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>

        <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nparticles</span><span class="p">):</span>
            <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
            <span class="n">id_</span><span class="p">,</span> <span class="n">elem</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="n">charge</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">2</span><span class="p">:</span><span class="mi">8</span><span class="p">]</span>
            <span class="n">p</span> <span class="o">=</span> <span class="n">Particle</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">y</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">y</span><span class="p">),</span> <span class="n">z</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">z</span><span class="p">),</span> <span class="n">molecule</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                         <span class="n">elem</span><span class="o">=</span><span class="n">elem</span><span class="p">,</span> <span class="n">charge</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">charge</span><span class="p">))</span>
            <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>

        <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
        <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>

        <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nbonds</span><span class="p">):</span>
            <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
            <span class="n">id_</span><span class="p">,</span> <span class="n">order</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">2</span><span class="p">:</span><span class="mi">6</span><span class="p">])</span>
            <span class="n">s</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">Bond</span><span class="p">(</span><span class="n">a</span><span class="o">=</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="n">b</span><span class="p">,</span> <span class="n">order</span><span class="o">=</span><span class="n">order</span><span class="p">))</span>

    <span class="n">s</span><span class="o">.</span><span class="n">objectify</span><span class="p">()</span>

    <span class="k">if</span> <span class="n">type_with</span><span class="p">:</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">s</span><span class="o">.</span><span class="n">apply_forcefield</span><span class="p">(</span><span class="n">type_with</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
            <span class="k">print</span><span class="p">(</span><span class="s1">&#39;forcefield typing with forcefield </span><span class="si">%s</span><span class="s1"> unsuccessful&#39;</span>
                  <span class="o">%</span> <span class="n">type_with</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">s</span></div>
    
    
<div class="viewcode-block" id="read_prepc"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.read_prepc">[docs]</a><span class="k">def</span> <span class="nf">read_prepc</span><span class="p">(</span><span class="n">prec_file</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.system.read_prepc</span>

<span class="sd">    Interprets prepc file and creates :class:`~pysimm.system.System` object</span>

<span class="sd">    Args:</span>
<span class="sd">        prepc_file: ac file name</span>

<span class="sd">    Returns:</span>
<span class="sd">        :class:`~pysimm.system.System` object</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="n">prec_file</span><span class="p">):</span>
        <span class="n">debug_print</span><span class="p">(</span><span class="s1">&#39;reading file&#39;</span><span class="p">)</span>
        <span class="n">f</span> <span class="o">=</span> <span class="nb">file</span><span class="p">(</span><span class="n">prec_file</span><span class="p">)</span>
    <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">prec_file</span><span class="p">,</span> <span class="nb">basestring</span><span class="p">):</span>
        <span class="n">debug_print</span><span class="p">(</span><span class="s1">&#39;reading string&#39;</span><span class="p">)</span>
        <span class="n">f</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">(</span><span class="n">prec_file</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">raise</span> <span class="n">PysimmError</span><span class="p">(</span><span class="s1">&#39;pysimm.system.read_pdb requires either &#39;</span>
                          <span class="s1">&#39;file or string as argument&#39;</span><span class="p">)</span>

    <span class="n">s</span> <span class="o">=</span> <span class="n">System</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;read using pysimm.system.read_ac&#39;</span><span class="p">)</span>

    <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span>
        <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">10</span><span class="p">):</span>
            <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
        <span class="k">while</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">():</span>
            <span class="n">tag</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">0</span><span class="p">])</span>
            <span class="n">name</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">type_name</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">2</span><span class="p">]</span>
            <span class="n">x</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">4</span><span class="p">])</span>
            <span class="n">y</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">5</span><span class="p">])</span>
            <span class="n">z</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">6</span><span class="p">])</span>
            <span class="n">charge</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">7</span><span class="p">])</span>
            <span class="n">elem</span> <span class="o">=</span> <span class="n">type_name</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">p</span> <span class="o">=</span> <span class="n">Particle</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span> <span class="n">type_name</span><span class="o">=</span><span class="n">type_name</span><span class="p">,</span> <span class="n">x</span><span class="o">=</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="o">=</span><span class="n">z</span><span class="p">,</span> <span class="n">elem</span><span class="o">=</span><span class="n">elem</span><span class="p">,</span> <span class="n">charge</span><span class="o">=</span><span class="n">charge</span><span class="p">)</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">tag</span><span class="p">]:</span>
                <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
            <span class="n">line</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
        <span class="k">break</span>

    <span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
    
    <span class="k">return</span> <span class="n">s</span></div>
    
<div class="viewcode-block" id="read_ac"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.read_ac">[docs]</a><span class="k">def</span> <span class="nf">read_ac</span><span class="p">(</span><span class="n">ac_file</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.system.read_ac</span>

<span class="sd">    Interprets ac file and creates :class:`~pysimm.system.System` object</span>

<span class="sd">    Args:</span>
<span class="sd">        ac_file: ac file name</span>

<span class="sd">    Returns:</span>
<span class="sd">        :class:`~pysimm.system.System` object</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="n">ac_file</span><span class="p">):</span>
        <span class="n">debug_print</span><span class="p">(</span><span class="s1">&#39;reading file&#39;</span><span class="p">)</span>
        <span class="n">f</span> <span class="o">=</span> <span class="nb">file</span><span class="p">(</span><span class="n">ac_file</span><span class="p">)</span>
    <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">ac_file</span><span class="p">,</span> <span class="nb">basestring</span><span class="p">):</span>
        <span class="n">debug_print</span><span class="p">(</span><span class="s1">&#39;reading string&#39;</span><span class="p">)</span>
        <span class="n">f</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">(</span><span class="n">ac_file</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">raise</span> <span class="n">PysimmError</span><span class="p">(</span><span class="s1">&#39;pysimm.system.read_pdb requires either &#39;</span>
                          <span class="s1">&#39;file or string as argument&#39;</span><span class="p">)</span>

    <span class="n">s</span> <span class="o">=</span> <span class="n">System</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;read using pysimm.system.read_ac&#39;</span><span class="p">)</span>

    <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">line</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;ATOM&#39;</span><span class="p">):</span>
            <span class="n">tag</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">])</span>
            <span class="n">name</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">2</span><span class="p">]</span>
            <span class="n">resname</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">3</span><span class="p">]</span>
            <span class="n">resid</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">4</span><span class="p">]</span>
            <span class="n">x</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">5</span><span class="p">])</span>
            <span class="n">y</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">6</span><span class="p">])</span>
            <span class="n">z</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">7</span><span class="p">])</span>
            <span class="n">charge</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">8</span><span class="p">])</span>
            <span class="n">type_name</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">9</span><span class="p">]</span>
            <span class="n">elem</span> <span class="o">=</span> <span class="n">type_name</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">p</span> <span class="o">=</span> <span class="n">Particle</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span> <span class="n">type_name</span><span class="o">=</span><span class="n">type_name</span><span class="p">,</span> <span class="n">resname</span><span class="o">=</span><span class="n">resname</span><span class="p">,</span> <span class="n">resid</span><span class="o">=</span><span class="n">resid</span><span class="p">,</span> <span class="n">x</span><span class="o">=</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="o">=</span><span class="n">z</span><span class="p">,</span> <span class="n">elem</span><span class="o">=</span><span class="n">elem</span><span class="p">,</span> <span class="n">charge</span><span class="o">=</span><span class="n">charge</span><span class="p">)</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">tag</span><span class="p">]:</span>
                <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">line</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;BOND&#39;</span><span class="p">):</span>
            <span class="n">tag</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">])</span>
            <span class="n">a</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">2</span><span class="p">])]</span>
            <span class="n">b</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">3</span><span class="p">])]</span>
            <span class="n">b</span> <span class="o">=</span> <span class="n">Bond</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="n">a</span><span class="o">=</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="n">b</span><span class="p">)</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">s</span><span class="o">.</span><span class="n">bonds</span><span class="p">[</span><span class="n">tag</span><span class="p">]:</span>
                <span class="n">s</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">b</span><span class="p">)</span>


    <span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
    
    <span class="k">return</span> <span class="n">s</span></div>


<div class="viewcode-block" id="read_pdb"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.read_pdb">[docs]</a><span class="k">def</span> <span class="nf">read_pdb</span><span class="p">(</span><span class="n">pdb_file</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.system.read_pdb</span>

<span class="sd">    Interprets pdb file and creates :class:`~pysimm.system.System` object</span>

<span class="sd">    Args:</span>
<span class="sd">        pdb_file: pdb file name</span>

<span class="sd">    Returns:</span>
<span class="sd">        :class:`~pysimm.system.System` object</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="n">pdb_file</span><span class="p">):</span>
        <span class="n">debug_print</span><span class="p">(</span><span class="s1">&#39;reading file&#39;</span><span class="p">)</span>
        <span class="n">f</span> <span class="o">=</span> <span class="nb">file</span><span class="p">(</span><span class="n">pdb_file</span><span class="p">)</span>
    <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">pdb_file</span><span class="p">,</span> <span class="nb">basestring</span><span class="p">):</span>
        <span class="n">debug_print</span><span class="p">(</span><span class="s1">&#39;reading string&#39;</span><span class="p">)</span>
        <span class="n">f</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">(</span><span class="n">pdb_file</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">raise</span> <span class="n">PysimmError</span><span class="p">(</span><span class="s1">&#39;pysimm.system.read_pdb requires either &#39;</span>
                          <span class="s1">&#39;file or string as argument&#39;</span><span class="p">)</span>

    <span class="n">s</span> <span class="o">=</span> <span class="n">System</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;read using pysimm.system.read_pdb&#39;</span><span class="p">)</span>

    <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">line</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;ATOM&#39;</span><span class="p">):</span>
            <span class="n">tag</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">6</span><span class="p">:</span><span class="mi">11</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span>
            <span class="n">name</span> <span class="o">=</span> <span class="n">line</span><span class="p">[</span><span class="mi">12</span><span class="p">:</span><span class="mi">16</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
            <span class="n">resname</span> <span class="o">=</span> <span class="n">line</span><span class="p">[</span><span class="mi">17</span><span class="p">:</span><span class="mi">20</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
            <span class="n">chainid</span> <span class="o">=</span> <span class="n">line</span><span class="p">[</span><span class="mi">21</span><span class="p">]</span>
            <span class="n">resid</span> <span class="o">=</span> <span class="n">line</span><span class="p">[</span><span class="mi">22</span><span class="p">:</span><span class="mi">26</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
            <span class="n">x</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">30</span><span class="p">:</span><span class="mi">38</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span>
            <span class="n">y</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">38</span><span class="p">:</span><span class="mi">46</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span>
            <span class="n">z</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">46</span><span class="p">:</span><span class="mi">54</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span>
            <span class="n">elem</span> <span class="o">=</span> <span class="n">line</span><span class="p">[</span><span class="mi">76</span><span class="p">:</span><span class="mi">78</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
            <span class="n">p</span> <span class="o">=</span> <span class="n">Particle</span><span class="p">(</span><span class="n">tag</span><span class="o">=</span><span class="n">tag</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span> <span class="n">resname</span><span class="o">=</span><span class="n">resname</span><span class="p">,</span> <span class="n">chainid</span><span class="o">=</span><span class="n">chainid</span><span class="p">,</span> <span class="n">resid</span><span class="o">=</span><span class="n">resid</span><span class="p">,</span> <span class="n">x</span><span class="o">=</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="o">=</span><span class="n">z</span><span class="p">,</span> <span class="n">elem</span><span class="o">=</span><span class="n">elem</span><span class="p">)</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">tag</span><span class="p">]:</span>
                <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>


    <span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

    <span class="k">return</span> <span class="n">s</span></div>


<div class="viewcode-block" id="compare"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.compare">[docs]</a><span class="k">def</span> <span class="nf">compare</span><span class="p">(</span><span class="n">s1</span><span class="p">,</span> <span class="n">s2</span><span class="p">):</span>
    <span class="k">print</span><span class="p">(</span><span class="s1">&#39;Particle Types:</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">pt</span> <span class="ow">in</span> <span class="n">s1</span><span class="o">.</span><span class="n">particle_types</span><span class="p">:</span>
        <span class="n">s2_pt</span> <span class="o">=</span> <span class="n">s2</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">pt</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">s2_pt</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">s2_pt</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="n">s2_pt</span> <span class="o">=</span> <span class="n">s2_pt</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="k">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="se">\n</span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="nb">vars</span><span class="p">(</span><span class="n">pt</span><span class="p">),</span> <span class="nb">vars</span><span class="p">(</span><span class="n">s2_pt</span><span class="p">)))</span>

    <span class="k">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n\n</span><span class="s1">Bond Types:</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">bt</span> <span class="ow">in</span> <span class="n">s1</span><span class="o">.</span><span class="n">bond_types</span><span class="p">:</span>
        <span class="n">s2_bt</span> <span class="o">=</span> <span class="n">s2</span><span class="o">.</span><span class="n">bond_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">bt</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">s2_bt</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">s2_bt</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="n">s2_bt</span> <span class="o">=</span> <span class="n">s2_bt</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="k">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="se">\n</span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="nb">vars</span><span class="p">(</span><span class="n">bt</span><span class="p">),</span> <span class="nb">vars</span><span class="p">(</span><span class="n">s2_bt</span><span class="p">)))</span>

    <span class="k">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n\n</span><span class="s1">Angle Types:</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">at</span> <span class="ow">in</span> <span class="n">s1</span><span class="o">.</span><span class="n">angle_types</span><span class="p">:</span>
        <span class="n">s2_at</span> <span class="o">=</span> <span class="n">s2</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">at</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">s2_at</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">s2_at</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="n">s2_at</span> <span class="o">=</span> <span class="n">s2_at</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="k">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="se">\n</span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="nb">vars</span><span class="p">(</span><span class="n">at</span><span class="p">),</span> <span class="nb">vars</span><span class="p">(</span><span class="n">s2_at</span><span class="p">)))</span>

    <span class="k">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n\n</span><span class="s1">Dihedral Types:</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">dt</span> <span class="ow">in</span> <span class="n">s1</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">:</span>
        <span class="n">s2_dt</span> <span class="o">=</span> <span class="n">s2</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">dt</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">s2_dt</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">s2_dt</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="n">s2_dt</span> <span class="o">=</span> <span class="n">s2_dt</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="k">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="se">\n</span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="nb">vars</span><span class="p">(</span><span class="n">dt</span><span class="p">),</span> <span class="nb">vars</span><span class="p">(</span><span class="n">s2_dt</span><span class="p">)))</span>

    <span class="k">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n\n</span><span class="s1">Improper Types:</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">it</span> <span class="ow">in</span> <span class="n">s1</span><span class="o">.</span><span class="n">improper_types</span><span class="p">:</span>
        <span class="n">s2_it</span> <span class="o">=</span> <span class="n">s2</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">it</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">s2_it</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">s2_it</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="n">s2_it</span> <span class="o">=</span> <span class="n">s2_it</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="k">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="se">\n</span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="nb">vars</span><span class="p">(</span><span class="n">it</span><span class="p">),</span> <span class="nb">vars</span><span class="p">(</span><span class="n">s2_it</span><span class="p">)))</span></div>


<div class="viewcode-block" id="get_types"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.get_types">[docs]</a><span class="k">def</span> <span class="nf">get_types</span><span class="p">(</span><span class="o">*</span><span class="n">arg</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.system.get_types</span>

<span class="sd">    Get unique type names from list of systems</span>

<span class="sd">    Args:</span>
<span class="sd">        write (optional): if True, write types dictionary to filename</span>

<span class="sd">    Returns:</span>
<span class="sd">        (ptypes, btypes, atypes, dtypes, itypes)</span>
<span class="sd">        *** for use with update_types ***</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">write</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;write&#39;</span><span class="p">)</span>

    <span class="n">ptypes</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>
    <span class="n">btypes</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>
    <span class="n">atypes</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>
    <span class="n">dtypes</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>
    <span class="n">itypes</span> <span class="o">=</span> <span class="n">ItemContainer</span><span class="p">()</span>

    <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">arg</span><span class="p">:</span>
        <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">particle_types</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">t</span><span class="o">.</span><span class="n">name</span> <span class="ow">and</span> <span class="n">t</span><span class="o">.</span><span class="n">name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="n">x</span><span class="o">.</span><span class="n">name</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">ptypes</span><span class="p">]:</span>
                <span class="n">ptypes</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">copy</span><span class="p">())</span>
        <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">bond_types</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">t</span><span class="o">.</span><span class="n">name</span> <span class="ow">and</span> <span class="n">t</span><span class="o">.</span><span class="n">name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="n">x</span><span class="o">.</span><span class="n">name</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">btypes</span><span class="p">]:</span>
                <span class="n">btypes</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">copy</span><span class="p">())</span>
        <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">angle_types</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">t</span><span class="o">.</span><span class="n">name</span> <span class="ow">and</span> <span class="n">t</span><span class="o">.</span><span class="n">name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="n">x</span><span class="o">.</span><span class="n">name</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">atypes</span><span class="p">]:</span>
                <span class="n">atypes</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">copy</span><span class="p">())</span>
        <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">t</span><span class="o">.</span><span class="n">name</span> <span class="ow">and</span> <span class="n">t</span><span class="o">.</span><span class="n">name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="n">x</span><span class="o">.</span><span class="n">name</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">dtypes</span><span class="p">]:</span>
                <span class="n">dtypes</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">copy</span><span class="p">())</span>
        <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">improper_types</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">t</span><span class="o">.</span><span class="n">name</span> <span class="ow">and</span> <span class="n">t</span><span class="o">.</span><span class="n">name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="n">x</span><span class="o">.</span><span class="n">name</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">itypes</span><span class="p">]:</span>
                <span class="n">itypes</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">copy</span><span class="p">())</span>

    <span class="k">if</span> <span class="n">write</span><span class="p">:</span>
        <span class="n">t_file</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="s1">&#39;types.txt&#39;</span><span class="p">,</span> <span class="s1">&#39;w+&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">ptypes</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">t_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;atom types</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">ptypes</span><span class="p">:</span>
            <span class="n">t_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">btypes</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">t_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">bond types</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">btypes</span><span class="p">:</span>
            <span class="n">t_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">atypes</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">t_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">angle types</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">atypes</span><span class="p">:</span>
            <span class="n">t_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">dtypes</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">t_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">dihedral types</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">dtypes</span><span class="p">:</span>
            <span class="n">t_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">itypes</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">t_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">improper types</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">itypes</span><span class="p">:</span>
            <span class="n">t_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
        <span class="n">t_file</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

    <span class="k">return</span> <span class="n">ptypes</span><span class="p">,</span> <span class="n">btypes</span><span class="p">,</span> <span class="n">atypes</span><span class="p">,</span> <span class="n">dtypes</span><span class="p">,</span> <span class="n">itypes</span></div>


<div class="viewcode-block" id="distance_to_origin"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.distance_to_origin">[docs]</a><span class="k">def</span> <span class="nf">distance_to_origin</span><span class="p">(</span><span class="n">p</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.system.distance_to_origin</span>

<span class="sd">    Calculates distance of particle to origin.</span>

<span class="sd">    Args:</span>
<span class="sd">        p: Particle object with x, y, and z attributes</span>
<span class="sd">    Returns:</span>
<span class="sd">        Distance of particle to origin</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="n">sqrt</span><span class="p">(</span><span class="nb">pow</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span> <span class="o">+</span> <span class="nb">pow</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span> <span class="o">+</span> <span class="nb">pow</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">z</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span></div>


<div class="viewcode-block" id="replicate"><a class="viewcode-back" href="../../pysimm.system.html#pysimm.system.replicate">[docs]</a><span class="k">def</span> <span class="nf">replicate</span><span class="p">(</span><span class="n">ref</span><span class="p">,</span> <span class="n">nrep</span><span class="p">,</span> <span class="n">s_</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">density</span><span class="o">=</span><span class="mf">0.3</span><span class="p">,</span> <span class="n">rand</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">print_insertions</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.system.replicate</span>

<span class="sd">    Replicates list of :class:`~pysimm.system.System` objects into new (or exisintg) :class:`~pysimm.system.System`.</span>
<span class="sd">    Can be random insertion.</span>

<span class="sd">    Args:</span>
<span class="sd">        ref: reference :class:`~pysimm.system.System`(s) (this can be a list)</span>
<span class="sd">        nrep: number of insertions to perform (can be list but must match length of ref)</span>
<span class="sd">        s_: :class:`~pysimm.system.System` into which insertions will be performed default=None</span>
<span class="sd">        density: density of new :class:`~pysimm.system.System` default=0.3 (set to None to not change box)</span>
<span class="sd">        rand: if True, random insertion is performed</span>
<span class="sd">        print_insertions: if True, update screen with number of insertions</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">ref</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
        <span class="n">ref</span> <span class="o">=</span> <span class="p">[</span><span class="n">ref</span><span class="p">]</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">nrep</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
        <span class="n">nrep</span> <span class="o">=</span> <span class="p">[</span><span class="n">nrep</span><span class="p">]</span>
    <span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="n">ref</span><span class="p">)</span> <span class="o">==</span> <span class="nb">len</span><span class="p">(</span><span class="n">nrep</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">s_</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
        <span class="n">s_</span> <span class="o">=</span> <span class="n">System</span><span class="p">()</span>
    <span class="n">s_</span><span class="o">.</span><span class="n">ff_class</span> <span class="o">=</span> <span class="n">ref</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">ff_class</span>
    <span class="n">s_</span><span class="o">.</span><span class="n">forcefield</span> <span class="o">=</span> <span class="n">ref</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">forcefield</span>
    <span class="n">s_</span><span class="o">.</span><span class="n">pair_style</span> <span class="o">=</span> <span class="n">ref</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">pair_style</span>
    <span class="n">s_</span><span class="o">.</span><span class="n">bond_style</span> <span class="o">=</span> <span class="n">ref</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">bond_style</span>
    <span class="n">s_</span><span class="o">.</span><span class="n">angle_style</span> <span class="o">=</span> <span class="n">ref</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">angle_style</span>
    <span class="n">s_</span><span class="o">.</span><span class="n">dihedral_style</span> <span class="o">=</span> <span class="n">ref</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">dihedral_style</span>
    <span class="n">s_</span><span class="o">.</span><span class="n">improper_style</span> <span class="o">=</span> <span class="n">ref</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">improper_style</span>

    <span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="n">ref</span><span class="p">:</span>
        <span class="n">r</span><span class="o">.</span><span class="n">set_mass</span><span class="p">()</span>
        <span class="n">r</span><span class="o">.</span><span class="n">center</span><span class="p">(</span><span class="s1">&#39;particles&#39;</span><span class="p">,</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="bp">True</span><span class="p">)</span>
        <span class="n">r</span><span class="o">.</span><span class="n">r</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">r</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="n">r</span><span class="o">.</span><span class="n">r</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">r</span><span class="o">.</span><span class="n">r</span><span class="p">,</span> <span class="n">distance_to_origin</span><span class="p">(</span><span class="n">p</span><span class="p">))</span>
        <span class="n">s_</span><span class="o">.</span><span class="n">molecule_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">r</span><span class="p">)</span>

    <span class="n">mass</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">r</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">ref</span><span class="p">):</span>
        <span class="n">mass</span> <span class="o">+=</span> <span class="n">r</span><span class="o">.</span><span class="n">mass</span> <span class="o">*</span> <span class="n">nrep</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
    <span class="n">mass</span> <span class="o">/=</span> <span class="mf">6.02e23</span>

    <span class="k">if</span> <span class="n">density</span><span class="p">:</span>
        <span class="n">volume</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">mass</span><span class="p">)</span> <span class="o">/</span> <span class="n">density</span>
        <span class="n">boxl</span> <span class="o">=</span> <span class="nb">pow</span><span class="p">(</span><span class="n">volume</span><span class="p">,</span> <span class="mi">1</span> <span class="o">/</span> <span class="mf">3.</span><span class="p">)</span> <span class="o">*</span> <span class="mf">1e8</span>
        <span class="n">s_</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xlo</span> <span class="o">=</span> <span class="o">-</span><span class="mf">1.</span> <span class="o">*</span> <span class="n">boxl</span> <span class="o">/</span> <span class="mf">2.</span>
        <span class="n">s_</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xhi</span> <span class="o">=</span> <span class="n">boxl</span> <span class="o">/</span> <span class="mf">2.</span>
        <span class="n">s_</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dx</span> <span class="o">=</span> <span class="n">s_</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xhi</span> <span class="o">-</span> <span class="n">s_</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xlo</span>
        <span class="n">s_</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">ylo</span> <span class="o">=</span> <span class="o">-</span><span class="mf">1.</span> <span class="o">*</span> <span class="n">boxl</span> <span class="o">/</span> <span class="mf">2.</span>
        <span class="n">s_</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">yhi</span> <span class="o">=</span> <span class="n">boxl</span> <span class="o">/</span> <span class="mf">2.</span>
        <span class="n">s_</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dy</span> <span class="o">=</span> <span class="n">s_</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">yhi</span> <span class="o">-</span> <span class="n">s_</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">ylo</span>
        <span class="n">s_</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zlo</span> <span class="o">=</span> <span class="o">-</span><span class="mf">1.</span> <span class="o">*</span> <span class="n">boxl</span> <span class="o">/</span> <span class="mf">2.</span>
        <span class="n">s_</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zhi</span> <span class="o">=</span> <span class="n">boxl</span> <span class="o">/</span> <span class="mf">2.</span>
        <span class="n">s_</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dz</span> <span class="o">=</span> <span class="n">s_</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zhi</span> <span class="o">-</span> <span class="n">s_</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zlo</span>

    <span class="n">num</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="k">for</span> <span class="n">j</span><span class="p">,</span> <span class="n">r</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">ref</span><span class="p">):</span>
        <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nrep</span><span class="p">[</span><span class="n">j</span><span class="p">]):</span>
            <span class="k">if</span> <span class="n">rand</span><span class="p">:</span>
                <span class="n">rotate_x</span> <span class="o">=</span> <span class="n">random</span><span class="p">()</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">pi</span>
                <span class="n">rotate_y</span> <span class="o">=</span> <span class="n">random</span><span class="p">()</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">pi</span>
                <span class="n">rotate_z</span> <span class="o">=</span> <span class="n">random</span><span class="p">()</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">pi</span>
                <span class="n">dx</span> <span class="o">=</span> <span class="n">s_</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xhi</span> <span class="o">-</span> <span class="n">s_</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xlo</span>
                <span class="n">dx</span> <span class="o">=</span> <span class="p">(</span><span class="o">-</span><span class="n">dx</span> <span class="o">/</span> <span class="mf">2.</span> <span class="o">+</span> <span class="n">r</span><span class="o">.</span><span class="n">r</span><span class="p">)</span> <span class="o">+</span> <span class="n">random</span><span class="p">()</span> <span class="o">*</span> <span class="p">(</span><span class="n">dx</span> <span class="o">-</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">r</span><span class="o">.</span><span class="n">r</span><span class="p">)</span>
                <span class="n">dy</span> <span class="o">=</span> <span class="n">s_</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">yhi</span> <span class="o">-</span> <span class="n">s_</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">ylo</span>
                <span class="n">dy</span> <span class="o">=</span> <span class="p">(</span><span class="o">-</span><span class="n">dy</span> <span class="o">/</span> <span class="mf">2.</span> <span class="o">+</span> <span class="n">r</span><span class="o">.</span><span class="n">r</span><span class="p">)</span> <span class="o">+</span> <span class="n">random</span><span class="p">()</span> <span class="o">*</span> <span class="p">(</span><span class="n">dy</span> <span class="o">-</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">r</span><span class="o">.</span><span class="n">r</span><span class="p">)</span>
                <span class="n">dz</span> <span class="o">=</span> <span class="n">s_</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zhi</span> <span class="o">-</span> <span class="n">s_</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zlo</span>
                <span class="n">dz</span> <span class="o">=</span> <span class="p">(</span><span class="o">-</span><span class="n">dz</span> <span class="o">/</span> <span class="mf">2.</span> <span class="o">+</span> <span class="n">r</span><span class="o">.</span><span class="n">r</span><span class="p">)</span> <span class="o">+</span> <span class="n">random</span><span class="p">()</span> <span class="o">*</span> <span class="p">(</span><span class="n">dz</span> <span class="o">-</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">r</span><span class="o">.</span><span class="n">r</span><span class="p">)</span>
                <span class="n">r_</span> <span class="o">=</span> <span class="n">r</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">rotate_x</span><span class="o">=</span><span class="n">rotate_x</span><span class="p">,</span> <span class="n">rotate_y</span><span class="o">=</span><span class="n">rotate_y</span><span class="p">,</span>
                            <span class="n">rotate_z</span><span class="o">=</span><span class="n">rotate_z</span><span class="p">,</span> <span class="n">dx</span><span class="o">=</span><span class="n">dx</span><span class="p">,</span> <span class="n">dy</span><span class="o">=</span><span class="n">dy</span><span class="p">,</span> <span class="n">dz</span><span class="o">=</span><span class="n">dz</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">r_</span> <span class="o">=</span> <span class="n">r</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>

            <span class="n">s_</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">r_</span><span class="p">,</span> <span class="n">change_dim</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">update_properties</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
            <span class="n">num</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="k">if</span> <span class="n">print_insertions</span><span class="p">:</span>
                <span class="n">verbose_print</span><span class="p">(</span><span class="s1">&#39;Molecule </span><span class="si">%s</span><span class="s1"> inserted&#39;</span> <span class="o">%</span> <span class="n">num</span><span class="p">)</span>

    <span class="n">s_</span><span class="o">.</span><span class="n">set_density</span><span class="p">()</span>
    <span class="n">s_</span><span class="o">.</span><span class="n">set_cog</span><span class="p">()</span>
    <span class="n">s_</span><span class="o">.</span><span class="n">set_velocity</span><span class="p">()</span>

    <span class="k">return</span> <span class="n">s_</span></div>
</pre></div>

           </div>
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2017, https://pysimm.org.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'../../',
            VERSION:'0.2',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true
        };
    </script>
      <script type="text/javascript" src="../../_static/jquery.js"></script>
      <script type="text/javascript" src="../../_static/underscore.js"></script>
      <script type="text/javascript" src="../../_static/doctools.js"></script>

  

  
  
    <script type="text/javascript" src="../../_static/js/theme.js"></script>
  

  
  
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.StickyNav.enable();
      });
  </script>
   

</body>
</html>